Sunday 28 June 2009

C sample questions papers


C language exam questions papers with solutions

(1)

#include"stdio.h"

void main(){

long double a=55555;

clrscr();

printf("%.2LE,%.2Le",a);

getch();

}


What will be output if you will execute above code?

(a) 5.56e+04, 5.56E+04

(b) 5.6e+04, 5.6E+04

(c) 5.56E+04, 5.56e+04

(d)Compiler error.

(e)None of the above.


(2)

#include"stdio.h"

void main(){

signed a=5;

unsigned b=5;

Tuesday 23 June 2009

c interview questions and answer










(1) If static storage in c will not work then what problem will you face?
(2) If extern storage in c will not work then what problem will you face?
(3) Why we cannot

Saturday 20 June 2009

C PROGRAMMING INTERVIEW QUESTIONS AND ANSWER



C programming interview
questions and answer for freshers



(1) If static storage in
c will not work then what problem will you face?

(2) If extern storage in
c will not work then what problem will you face?

(3) Why we cannot
initialize extern variables?

(4) What is trigraph in
C?

(5) Why char data type
can store two characters at a time?

(6) What is prototype of
printf function?

Answer

Cyclic nature of data type in C




In C some data types shows one special properties that when we assign a value beyond range of that data type then it will not any compiler error but assign a number according to some cyclic order. This property is known as cyclic nature of data type.


Data type which shows cyclic nature:

(a) char

(b) int

(c) long int

Data type which doesn’t show cyclic nature:

(a) float

(b) double

(c)

What is prototype of a function in C programming



What is prototype of a function in c
programming?



Declaration of function
is known as prototype of a function. Prototype of a function means



(1) What is return
type of function?

(2) What parameters
are we passing?

(3) For example
prototype of printf function is:



int printf(const char *, …);



I.e. its return type is
int data type, its first parameter constant character pointer and

Memory representation of double in C



Memory representation of double in c programming
language



Size of double is 64 bit. This is used
as:



1. 52 bit: for mantissa

2. 11 bit: for exponent (including one
signed bit of exponent)

3. 1 bit: for signed bit of mantissa



Memory representation of: double a = -3.3;



For
this you have to follow following steps:









Step1: convert the number (3.3) into binary form binary
value

Friday 19 June 2009

Memory representation of float data type in C.




Size of float data type is 32 bit. Its 32 bit is used as:
1. 23 bit: for mantissa
2. 8 bit: for exponent(including one signed bit of exponent)
3. 1 bit: for signed bit of mantissa





Memory representation of: float a = -3.3f;












For this you have to follow following steps:





Step1: convert the number (3.3) into binary form binary value of 3.3 is

Memory representation of long int





Memory
representation of unsigned long int: unsigned long inta=8888855555;



It is 32-bit
data type and all its 32 bit is data bit.



Binary
equivalent of 888885555 is: 110100 11111011 01010001 00110011

For 32 bit we
will add 2 zero in the left side i.e. 00110100 11111011 01010001 00110011. Here



A is 00110100

B is 11111011

C is 01010001

D is 00110011



Memory representation: 






Memory representation of int data type in C



Memory representation
of int data type in c programming language



int
may be signed or unsigned both have different memory representation.


1. Memory representation of:



unsigned int a=7;


It is 16-bit data type and all 16 bit is data
bit.
Binary equivalent of 7 is: 111
for 16 bit we will add 13 zero in the left side i.e. 00000000 00000111
Since Turbo C is based on 8085 microprocessor

What is endianness of a processor?


Endianness of a processor

If the size of data type
is more than one byte then endanness decide the memory representation of data type.
There are two types of microprocessor according to endianness.


Little-endian:

The processors which follow the following memory representation of
data are known as little-endian processor.







First A will fill then B then C then D then E and so on from

Memory representation of char data type in C

Char data types may be signed or unsigned. Size
of char data type is 8 bit. Both signed and unsigned have different memory
representation.


Memory representation of unsigned
char: In
unsigned char all 8 bit is used as data bit


Memory representation of unsigned char a= 7;

Binary equivalent of 7
is:  111

For 8 bit we will add 5
zero in the left side i.e. 00000111. In
the memory:





Here MSD

What is const and volatile qualifier in C programming?



Value of any
variable can be changed either by program or external device. Keywords const and volatile are not opposite to each
other.


Const:





When any
variable has qualified with const keyword in declaration
statement then it is not possible to assign any value or
modify it by the program. But indirectly with the help of pointer its value can
be changed.
When any variable is not

What is size of each data types in C programming?



Size of data type depends upon microprocessor. Each microprocessor defines its
own word length. On the basis of word length in general we can say:


1. Size of int is word length.


2. Size of short int can be
>= word length/2 but <=word length Size of long int can be <= 2*word
length but >=word length.


3. Size of char, float, double, long
double is always fix.


4. Size of enum is size of

How can you say typedef is also a storage class?



If we will
write following C code



#include

int main(){

typedef static int integer;

integer p=25;

printf(“%d”,p);

return 0;

}



Output: Compiler
error-Too many storage class


It is not necessary that each primary data type support all five group of
quantifier.

How can you say typedef is also a storage class?

Answer: If we will write following C code void main(){ typedef static int integer; Integer p=25; Printf(“%d”,p); } Output: Compiler error-Too many storage class
It is not necessary that each primary data type support all five group of quantifier.

What is qualifier or modifier of data type in C programming?



Qualifier or modifier of data type qualifies the
primary data types. There are five group of qualifier in C.








Group



Qualifier



Default qualifier





1



auto, register,
static, auto

extern, typedef



auto







2



signed, unsigned         



signed





3



short, long              



not short, not long

How many types of data are in C programming language?






In c programming language, there are three types of data. Which are:



Pointer to function in C programming

Pointer to function:

Monday 15 June 2009

Function recursion in C programming


Calling of same function
from its function body is known as function recursion. It is alternative of
loop. Any c program which is possible using loop it must be possible using
function recursion. Simple example:



Find the sum of all even
numbers from 0 to 20 using function recursion. Program:



int main(){

int total;

total=sum(2);

printf("%d",total);

return 0;

}

int sum(int i){

static 

Friday 12 June 2009

Renaming of function in C programming




In c we can typedef the function declaration. It is useful when function declaration is too complex and we have to give any simple name or if we have to create more numbers of function of the same type.

typedef void govinda(int);

void main(){

    govinda one,two;

    one(1);

    two(2);

    getch();

}

void one(int x){

    printf("FROM ONE %d",x);

}

void two(int y){

    printf("\

Tuesday 9 June 2009

Why we should use the function?

1. Function reduces the redundancy of code. Example: 1 Write a c program to find the sum of: 1! /5+ 2! /4+ 3! /3+ 4! /2+ 5! /1 without using function (Except main function). Where! Symbol indicates factorial of any number. void main(){ int num, sum=0; int fact1,fact2,fact3,fact4,fact5; fact1=fact2=fact3=fact4=fact5=1; num=0; while(num<=0){ fact1 =fact1+fact1*

Friday 5 June 2009

What is data segment?


Answer:Segment number 8 has special name which is known as data segment.
It has divided into four parts.
1. Stack area:-
All automatic variables are created into stack area.Default storage class of any local variable is auto.This variable may be int, char, float, array, pointer, struct, union etc.It also return function argument and return address.It follow LIFO data structure. It has two part

What is necessity of segmentation?

Answer:
Physical address are 20 bit.But we have no pointer of 20 bit.So pointer can not access whole residential address .So to solve this problem we have three different pointer and segmentation has done.

What is segmentation?

Answer:


Residential memory of RAM of size 1MB has divided into 16 equal part.These part is called segment.Each segment has size is 64KB.1MB=16*64KBThis process of division is known as segmentation.

What is physical address ?

20 bit address of the memory cell is known as physical address or real address.In 20 bit we can represent address from 0x00000 to 0xFFFFF.

What is residence memory in c programming ?




RAM has divided into two parts:
(1) Extended memory (useless)
(2) Residence memory : When any program is executed it is stored in the residence memory .For turbo c, it has 1MB residence memory i.e when we open turbo c it store 1MB in the RAM.