You are on page 1of 32

1. Which of the following language is predecessor to C Programming Language?

A B BCPL C++

2. C programming language was developed by

Dennis Ritchie Ken Thompson Bill Gates Peter Norton

3. C was developed in the year ___

1970 1972 1976 1980

4. C is a ___ language

High Level Low Level Middle Level Machine Level

5. C language is available for which of the following Operating Systems?

DOS Windows Unix All of these

6. Which of the following symbol is used to denote a pre-processor statement?

! # ~ ;

7. Which of the following is a Scalar Data type

Float Union Array Pointer

8. Which of the following are tokens in C?

Keywords Variables Constants All of the above

9. What is the valid range of numbers for int type of data?

-32768 to -65536 to
0 to 256 No specific range
+32767 +65536

10. Which symbol is used as a statement terminator in C?

! # ~ ;

11. Which escape character can be used to begin a new line in C?

\a \b \m \n
12. Which escape character can be used to beep from speaker in C?

\a \b \m \n

13. Character constants should be enclosed between ___

Single quotes Double quotes Both a and b None of these

14. String constants should be enclosed between ___

Single quotes Double quotes Both a and b None of these

15. Which of the following is invalid?

‘’ ““ ‘a’ ‘abc’

16. The maximum length of a variable in C is ___

8 16 32 64

17. What will be the maximum size of a float variable?

1 byte 2 bytes 4 bytes 8 bytes

18. What will be the maximum size of a double variable?

1 byte 4 bytes 8 bytes 16 bytes

19. A declaration float a,b; occupies ___ of memory

1 byte 4 bytes 8 bytes 16 bytes

20. The size of a String variable is

1 byte 8 bytes 16 bytes None of these


(1) What will be output of the following program ?
void main()
{ int i;
clrscr();
printf("india"-'A'+'B');

getch();
}
(2)What will be output of the following program ?
void main()
void main()
{ int i;
clrscr();
printf(5+"Raja hindustani");

getch();
}
(3) What will be output of the following program ?
void main()

void main()
{
clrscr();
printf("\ttare\bjamin\0par");

getch();

(4) What will be output of the following program ?


void main()
{
clrscr();
if(sizeof(!6.0))
printf("%d",sizeof(6.0,2));
else
printf("i don't know");
getch();
}

(5) What will be output of the following program ?


void main()
{
clrscr();
printf("RAJA HINDUSTANI"+'\11');
getch();
}

(6) What will be output of the following program ?


void main()
{
const int p=60;
(int)p=40;
clrscr();
printf("%d",p);
getch();
}

(7) What will be output of the following program ?


void main()
{
const int i=60;
int *p;
p=&i;
*p=40;
clrscr();
printf("%d",i);
getch();
}

(8) What will be output of the following program ?


void main()
{
char a=256;
int b=2;
int c;
c=a+b;
clrscr();
printf("%d",c);
getch();
}

(9) What will be output of the following program ?


void main()
{
float a=3.4;
int b=2;
int c;
c=a+b;
clrscr();
printf("%d",c);
getch();
}
(10) What will be output of the following program ?
void main()
{
int i=66,x=-3;
clrscr();
printf((x>0)?"%d":"%c",i);
getch();
}
Solution:
(1) ndia
(2) hindustani

(3) tarjamin

(4) 2

(5) USTANI

(6) 40

(7) 40

(8) 5538
(9) 5

(10) B

Memory Related questions of c programming language


(1) What will be output of following program?
void main()
{
int a=5,b=6,c=7;
printf(“%d,%d,%d”);
}
Output: 7 6 5
Explanation:
Default storage class int a=5 is auto .Since it automatic variable
it will create in the stack area.
It will store in the stack as
Stack always follows LIFO data structure.
In the printf statement name of variable is not written explicitly.
So default output will content of
stack which will be in the LIFO order i.e. 7 6 5.
(2)What will be output of following program
void main()
{
int a=5 ,b,c=7;
printf(“%d %d %d”)
}
Output: 7 5 garbage value
Explanation:
Automatic variable a and c has initialized while b has not
initialize. Initialize variable are more nearer than non
initialize variable .They will be stored in the stack. So due to
LIFO first output will be 7 then 6 (since a is more nearer than
b with respect to c) then any garbage value will be output
which is present in the stack.
(3)What will be output of following program?
void main()
{
int a=5,b=6,c=7;
printf(“%d,%d,%d”);
}
Output: 7 6 5
Explanation:
Default storage class int a=5 is auto. Since it automatic variable
it will create in the stack area.
It will store in the stack as

Stack always follows LIFO data structure.


In the printf statement name of variable is not written explicitly.
So default output will content of
stack which will be in the LIFO order i.e. 7 6 5.
(4)What will be output of following program
void main()
{
int a=5 ,b,c=7;
printf(“%d %d %d”);
}
Output: 7 5 garbage value
Explanation:
Automatic variable a and c has been initialized while b has
not been initialized. Initialize variable are more nearer than
non initialize variable .They will be stored in the stack. So
due to LIFO first output will be 7 then 6 (since a is more
nearer than b with respect to c) then any garbage value will be
output which is present in the stack.
Memory map questions with solution in c programming language

1.Good questions on Memory map

knowledge before staring c programming language

2. List the five c compiler?

3. Describe turbo c compiler?

4. What is hexadecimal number system?

5. What will be address range which can be represented in 20 bit?

6. What is difference between TSR and TSO program?

7. Why there are so many c compilers?

8. What is difference between .com program and .exe program?

9. How many type of warrning in c.

Memory Organization : DOS as example

10. What is memory cell?


11. What is residence memory?

12. What is physical address?

13. What is segmentation?

14. What is offset address?

15. What is necessity of segmentation?

16. Write a program to find the offset address of any variable?

17. What is data segment?

Name of C programming language compiler.


Answer:
Name Work on O.S Name of microprocessor
1. Turbo c M.S DOS 8086
2. Ansic c LINUX/UNIX 80386
3. Borland c WINDOW 80386
4. Microsoft c M.S DOS 8086
5. Visual c++ WINDOW 80386

Note:- 8086 is 16 bit microprocessor while 80386 is 32 bit microprocessor.


Describe Turbo c compiler.
Answer:
Turbo c compiler is one of the most popular c compilers. It is based on DOS operating
system. It uses 8086 microprocessor which is 16 bit microprocessor. It has 20 address buses
and 16 data bus. Its word length is two byte.
Difference between TSR and TSO program .
TSO means terminate but stay outside. It is those program, which release the main memory
after the execution of the program. E.g. Vcd cutter, turbo c compiler.

TSR means terminate but stay residence .It is those program, which after the execution of the
program does not release the RAM (main memory).e.g. antivirus.
Difference between .com program and .exe program.
Answer:
Both .com and .exe program are executable program but .com program execute faster than
.exe program. All drivers are .com program.
Warning code in c programming
Warning Message xxx

ANSI Violations
Assigning 'type' to 'enumeration' eas
Bit fields must be signed or unsigned int bbf
Both return and return with a value used ret
Declare type 'type' prior to use in prototype dpu
Division by zero zdi
Hexadecimal value contains more than 3 digits big
Initializing 'enumeration' with 'type' bei
'identifier' is declared as both external and static ext
Ill-formed pragma ill
Initialization is only partially bracketed pin
Redefinition of 'macro' is not identical dup
Suspicious pointer conversion sus
Undefined structure 'structure' stu
Void functions may not return a value voi

Frequent Errors

Code has no effect eff


Function should return a value rvl
Parameter 'parameter' is never used par
Possible use of 'identifier' before definition def
Possibly incorrect assignment pia
Unreachable code rch

Less Frequent Errors

Ambiguous operators need parentheses amb


Array variable 'identifier' is near ias
Call to function with no prototype pro
Call to function 'function' with no prototype pro
Condition is always false wccc
Condition is always true wccc
'identifier' declared but never used use
'identifier' is assigned a value that is never used aus
No declaration for function 'function' nod
Structure passed by value stv
Superfluous & with function amp

Portability Warnings

Constant is long cln


Constant out of range in comparison rng
Conversion may lose significant digits sig
Nonportable pointer comparison cpt
Nonportable pointer conversion rpt
Mixing pointers to signed and unsigned char ucp
Data type questions with solution

(1)
What will be output of following program
?
void main()
{
char i=13;
clrscr();
while(i)
{
i++;
}
printf("%d",i);
getch();
}

Output: 0
Explanation:
while( i) will true if i non zero number .
while (i) will false only when i=0.
Since i is char type of data which is cyclic in nature.

i will get maximum value to 127 the minimum value


-128 then it will be zero .When i=0 ,while condition
will false and i will come outside the loop and at
that time value of I is zero.
(2)
What will be output :
void main()
{
float a= -3.3f;
int i;
unsigned char *p=&a;
for(int i=0;i<4;i++)>
{
printf(“%d “,*p); p++;
}
}
Ans : Output : 52 52 83 192 Explanation :

p is char pointer which is holding the intial address


variable a.
Let p store address 500. Memory repersentation of
-3.3f is

first output :
*p mean content at the location 500 which is
00110011 .Its decimal value is 52
Second output:
P+1 mean next memory location i.e 501 (since p is
char pointer which is 8 bit data type so it will incrses
only 8 bit)
*(p+1) mean contentt at the location 501 which is
00110011 .Its decimal value is 52
Third output:
P+2 mean next memory location i.e 502
*(p+2) mean content at the location 502 which is
01010011 .Its decimal value is 83
Fourth output:
P+3 mean next memory location i.e 503
*(p+3) mean content at the location 503 which is
11000000 .Its decimal value is 192
(3)

What will be output:


void main()
{
int a=5,b=6,c=7;
printf(“%d,%d,%d”);
}
Ans:
Output: 7 6 5
Explanation:
Default sotrage class int a=5 is auto.Since it
automatic variable it
will create in the stack area.It will store in the stack
as:

Stack always follows LIFO datastructure.In the printf


statement
name of variable is not written explicitly.So default
output will
content of Stack which will be in the LIFO order i.e 7
6 5.
(memory map)

Data type in c programming

(1) How many type of data c?


Ans:
In c, there are three types of data.

(2) What is qualifier or modifier of data type?


Ans:
It qulaify the primary data type.There are five group of qualifier in C.
Group Qualifier
1 storage class: auto (default), register, static, extern
2 for signe: signed (default), unsgined.
3 short, long
4 const
5 volatile
(There is another type qualifier near, far, huge, which qualify only pointer type
data type)
We can write all five (one for each group) qualifiers for same data type. If we
will not write then it will take its default quantifier.We can write quantifier in
any order.We cannot write two qualifier of the same group.
E.g short unsigned volatile const int a=5;
It is right. Qualifier of each group is:
Group Qualifier Comment
1 auto since here not storage class quatifier has writtent, so compiler has
used its default value.
2 unsigned
3 short
4 const
5 volatile
E.g static auto int a=5;
It is wrong, because we cannot write two qualifier of the same group.Both
static and auto comes under group 1 i.e storage class.
Note. There is not any keyword for the opposite const and volatile .So if does
not write qualifier const it means the default qualifier is opposite of
const.Same this happen for volatile.Default qualifier of group 3 has also not
any keyword .It is between the short and long i.e normal data type.
It not necessary that each primary data type support all five group of
quantifier.
Data type Qualifier (which has meaning)
char all qualifiers except short, long
int all qualifier
float all qualifiers except short, long, signed, unsigned
double all qualifier except short, signed, unsigned
void not any qualifier

(3) What is size of each data type?


Size of data type depends upon microprocessor.
Size of int is word length
Size of short int can be >= word length/2 but <=word length Size of long int can
be <= 2*word length but >=word length
Size of char, float, double, long double is always fix.
Size of enum is size of int.
Turbo C is based on 8086 microprocessor and its word length is two byte

For TURBO C
Data type size (in byte)
char 1
Short int 2
int 2
long int or long 4
enum 2
float 4
double 8
long double 10
(4) What is const and volatile qualifier?
Ans:
Value of any variable can be changed either by program or external
device.const. and volatile is not opposite to each other.
Const : when any variable has qualified with const keyword in declaration
statement then later it is not possible to assign any value or modify by the
program.But indirectly with the help of pointer its value can be changed.
When any variable is not qualified by const variable then it’s default qualifier is
not const .There is not any keyword for not const.It’s meaning is that value of
variable can be changed after the declaration statement by the program.
e.g
What will be output?
void main()
{
const int a=5;
a++;
printf(“%d”,a);
}
Ans: compiler error, we cannot modify const variable.

Volatile: when any variable has qualified by volatile keyword in declaration


statement then value of variable can be changed by any external device or
hardware interrupt.
If any variable has not qualified by volatile keyword in declaration statement,
then then compiler will take not volatile as default quantifier .There is not any
special keyword for not volatile.Not volatile means when any variable has
qualified by volatile keyword in declaration statement then value of variable
cannot be changed by any external device or hardware interrupt.
(5) What is meaning of the declaration:
const volatile int a=6;
Ans:
Value of variable cannot be changed by program (due to const) but its value
can be changed by external device or hardware interrupt (due to volatile).
(6) Explain enum data type ?
Ans: enum is keyword with the help of enum we can make large number of
constant of type int
Syntax: enum [.]{ [=], …}[]
Note. [ ] indicate that they are optional.
= +1
Default initial value of first constant is zero.
Value of must be within range of integer.
e.g void main()
{
enum colour { green,red=5,blue,white,yellow=10,pink };
printf(“%d %d %d %d %d %d,green,red,blue,white,yellow,pink}
};

Output: 0 5 6 7 8 10 11
(7) What is use of typedef keyword ?
Ans:
typedef keyword assigns the symbol name of data type definition.Where symbol
name is valid identifier.
e.g
void main()
{
typedef unsigned long int world;
world a=45;
printf(“%d”,a);
}
Output : 45
typedef never creates a new data type .It only produce a new name of existing
data type.

(8) What is constant? How many type of constant in C?


Ans: Constant is fixed value which can not be changed by the program during
the execution.
Constants are classified as

We can make any identifier constant by


const keyword:
e.g const int total=5;
now total is constant.We cannot change the value of total.
define directive :
e.g #define fraction 1.5
Preprocessor are processed before the actual compilation. So it paste will
paste the 1.5 in place of fraction in the program before actual compilation.
enum keyword :
e.g enum size { a=8,b=7,c,d,e};
now a,b,c,d and e are constant we cannot change the value of a by program.

(9) How char data type is represented in the memory?


Ans:
char data type may be signed or unsigned .Both has different memory
representation.Both are 8 bit data type.
unsigned char:
All 8 bit is used as data bit.
e.g 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 is most significant digit and LSD is list significant digit.
signed char:
1 bit: signed bit
7 bit: data bit
Note: In C, negative number is stored in the 2’s complement format.
Signed bit is 0: Number is positive.
Signed bit is 1: Number is negative.

e.g memory representation of char a=7;


Binary equivalent of 7 is 111
For 8 bit we will add 5 zero in the left side i.e 00000111
Memory representation:

e.g memory representation of char a= -7;


Binary equivalent of 7 is 111
For 8 bit we will add 5 zero in the left side i.e 00000111
Since a is negative number so it will store in the memory in the 2’s complement
format

Memory representation:
(10) What is endianness of processor?
Ans:
If the size of data type is more than one byte then endianness decides the
memory representation of data type. There are two type of endianness.

Little-endian: The processor which follow the following memory representation


of data is known as little-endian processor.

First A will fill then B then C then D then E and so on from right to left.
Example of processor: 8085,8086,8088,80286,80386,p1,p2 etc.
Big-endian: The processor which follow the following memory representation of
data is known as big-endian processor.

First A will fill then B then C then D then E from right to left.
Example of processor: Motorola, IBM pc etc.

(11) How int data type is represented in the memory?


Ans:
int may be signed or unsigned both has 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 which follow little-endian.
Here A is 00000111 and B is 00000000
Memory representation :

Note: same memory representation will be of : unsigned short int a=7;


2. Memory representation of: unsigned long int a=8888855555;
It is 32-bit data type and all 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 :
3.
(a) Memory representation of: int a=7 or signed int a=7;
It is 16 bit data type .
15 bit: data bit
1 bit: signed bit
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Here
A is 00000111
B is 00000000
Memory representation :

Note: same memory representation will be of: short int a=7 or signed short int
a=7;

(b) Memory representation of : int a= -7 or signed int a= -7;


It is 16 bit data type .
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Since a is negative number so it will first convert in the 2’s complement format
before stored in the memory.

Memory representation :

Note: same memory representation will be of : short int a=-7 or signed short int
a=-7;

(4)
(a) Memory representation of : long int a=8888855555 or signed long int
a=8888855555;
It is 32 bit data type .
31 bit : data bit
1 bit : signed bit
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 16 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001
00110011
Here
A is 00110011
B is 01010001
C is 11111011
D is 00110100
Memory representation :

(b) Memory representation of : int a= -8888855555 or signed int a=


-8888855555;
It is 32 bit data type .
Bit no 31 is signed bit.
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 32 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001
00110011

Since a is negative number so it will first convert in the 2’s complement format
before stored in the memory.
Memory representation :

(12) How float,double data type is represented in the memory ?


Ans:
Float : It is 32 bit data type.
23 bit : for mantissa
8 bit : for exponent ( including one signed bit of exponent )
1 bit : for signed bit of mantissa

e.g Memory representation of float a = -3.3f;


step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… =
1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010011 00110011 001100110 (only first 23 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 127 in the exponent and convert in the binary number form ( since
in 7 bit of exponent except signed bit maximum possible number is 1111111 )
Exponent= 127+1=128
Binary form of 128 is 1000000 0
Store first bit i.e 0 at the 0 position of exponent. (in figure red colour zero)
Store rest 7 bit at 1 to 7 bit of exponent from right to left (in figure red color 1
to 7)
Step 7: store the 23 bit mantissa at 1 to 23 bit position in as shown in figure
.Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa
as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure
and so on.
In the memory -3.3 is represented as :

double:
It is 64 bit data type.
52 bit : for mantissa
11 bit : for exponent (including one signed bit of exponent )
1 bit : for signed bit of mantissa

e.g Memory representation of double a = -3.3 ;


step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… =
1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010 01100110 01100110 01100110 01100110 01100110 01100110
(only first 52 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 1023 in the exponent and convert in the binary number form
( since in 10 bit of exponent except signed bit maximum possible number is
1111111111 )
Exponent= 1023+1=1024
Binary form of 1024 is 10000000000
Store first 4 bit i.e 0000 at the 0 to 3 position of exponent. (in figure blue
colour digit)
Store rest 7 bit at 4 to 10 bit of exponent from right to left (in figure blue color
4 to 10)
Step 7: store the 52 bit mantissa at 1 to 52 bit position in as shown in figure
.Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa
as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure
and so on.
In the memory -3.3 is repersente as :

(13) What will be output :

void main()
{
float a= -3.3f;
int i;
unsigned char *p=&a;
for(int i=0;i<4;i++)>
{

printf(“%d “,*p);

p++;

}
Ans : Output : 52 52 83 192

Explanation :

p is char pointer which is holding the intial address variable a. Let p store
address 500 . memory repersentation of -3.3f is first output : *p mean content
at the location 500 which is 00110011 .Its decimal value is 52 Second output:
P+1 mean next memory location i.e 501 (since p is char pointer which is 8 bit
data type so it will incrses only 8 bit) *(p+1) mean contentt at the location 501
which is 00110011 .Its decimal value is 52 Third output: P+2 mean next memory
location i.e 502 *(p+2) mean content at the location 502 which is 01010011 .Its
decimal value is 83 Fourth output: P+3 mean next memory location i.e 503
*(p+3) mean content at the location 503 which is 11000000 .Its decimal value is
192 (14) what is meaning of cyclic nature of the data type ? Ans: In the data
type char ,int,long int if we assign the value beyond range of of data type
instead of giving compiler error it repeat the same value in cyclic order.
unsigned char : Range of unsigned char is 0 to 255 . If we will assign a value
greater than 255 then value of variable will be changed to a value if we will
move clockwise direction as shown in the figure according to number.If number
is less than 0 then move anti clockwise direction. If number is X where X is
greater than 255 then New value = X % 256 If number is Y where Y is less than 0
then New value = 256 – ( Y% 256 ) signed char : Range of unsigned char is -128
to 127 . If we will assign a value greater than 127 then value of variable will be
changed to a value if we will move clockwise direction as shown in the figure
according to number. If number is less than -128 then move anti clockwise
direction. If number is X where X is greater than 127 then p = X % 256 if p
<=127 new value = p else new value = p - 256 If number is Y where Y is less
than -128 then p = Y % 256 If p <= 127 New value = -p else New value = 256 -p
unsigned int : Range of unsigned int is 0 to 653535 . If we will assign a value
greater than 65535 then value of variable will be changed to a value if we will
move clockwise direction as shown in the figure according to number.If number
is less than 0 then move anti clockwise direction. If number is X where X is
greater than 65535 then New value = X % 65536 If number is Y where Y is less
than 0 then New value = 65536– ( Y% 65536) signed int : Range of unsigned int is
-32768 to 32767 . If we will assign a value greater than 32767 then value of
variable will be changed to a value if we will move clockwise direction as
shown in the figure according to number. If number is less than -32768 then
move anti clockwise direction. If number is X where X is greater than 32767
then p = X % 65536 if p <=32767 new value = p else new value = p - 65536 If
number is Y where Y is less than -32768 then p = Y % 65536 If p <= 32767 New
value = -p else New value = 65536 -p Same thing is occured in case of signed
long int and unsigned long int.

c coding question with solution


(1) How many type of data c?
Ans:
In c, there are three types of data.
(2) What is qualifier or modifier of data type?
Ans:
It qulaify the primary data type.There are five group of qualifier in C.
Group Qualifier
1 storage class: auto (default), register, static, extern
2 for signe: signed (default), unsgined.
3 short, long
4 const
5 volatile
(There is another type qualifier near, far, huge, which qualify only pointer type
data type)
We can write all five (one for each group) qualifiers for same data type. If we
will not write then it will take its default quantifier.We can write quantifier in
any order.We cannot write two qualifier of the same group.
E.g short unsigned volatile const int a=5;
It is right. Qualifier of each group is:
Group Qualifier Comment
1 auto since here not storage class quatifier has writtent, so compiler has
used its default value.
2 unsigned
3 short
4 const
5 volatile
E.g static auto int a=5;
It is wrong, because we cannot write two qualifier of the same group.Both
static and auto comes under group 1 i.e storage class.
Note. There is not any keyword for the opposite const and volatile .So if does
not write qualifier const it means the default qualifier is opposite of
const.Same this happen for volatile.Default qualifier of group 3 has also not
any keyword .It is between the short and long i.e normal data type.
It not necessary that each primary data type support all five group of
quantifier.
Data type Qualifier (which has meaning)
char all qualifiers except short, long
int all qualifier
float all qualifiers except short, long, signed, unsigned
double all qualifier except short, signed, unsigned
void not any qualifier
(3) What is size of each data type?
Size of data type depends upon microprocessor.
Size of int is word length
Size of short int can be >= word length/2 but <=word length Size of long int can
be <= 2*word length but >=word length
Size of char, float, double, long double is always fix.
Size of enum is size of int.
Turbo C is based on 8086 microprocessor and its word length is two byte

For TURBO C
Data type size (in byte)
char 1
Short int 2
int 2
long int or long 4
enum 2
float 4
double 8
long double 10
(3) What is const and volatile qualifier?
Ans:
Value of any variable can be changed either by program or external
device.const. and volatile is not opposite to each other.
Const : when any variable has qualified with const keyword in declaration
statement then later it is not possible to assigne any value or modify by the
program.But indirectly with the help of pointer its value can be changed.
When any variable is not qualified by const variable then it’s default qualifier is
not const .There is not any keyword for not const.It’s meaning is that value of
variable can be changed after the declaration statement by the program.
e.g
What will be output?
void main()
{
const int a=5;
a++;

printf(“%d”,a);
}
Ans: compiler error, we cannot modify const variable.

Volatile: when any variable has qualified by volatile keyword in declaration


statement then value of variable can be changed by any external device or
hardware interrupt.
If any variable has not qualified by volatile keyword in declaration statement,
then then compiler will take not volatile as default quantifier .There is not any
special keyword for not volatile.Not volatile means when any variable has
qualified by volatile keyword in declaration statement then value of variable
cannot be changed by any external device or hardware interrupt.
(4) What is meaning of the declaration:
const volatile int a=6;
Ans:
Value of variable cannot be changed by program (due to const) but its value
can be changed by external device or hardware interrupt (due to volatile).
(6) Explain enum data type?
Ans:

(5) What is constant? How many type of constant in C?


Ans:

(6) How char data type is repersented in the memory?


Ans:
char data type may be signed or unsigned .Both has different memory
repersentation.Both are 8 bit data type.
unsigned char:
All 8 bit is used as data bit.
e.g memory repersentation 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 is most significant digit and LSD is list significant digit.
signed char:
1 bit: signed bit
7 bit: data bit
Note: In C, negative number is stored in the 2’s complement format.
Signed bit is 0: Number is positive.
Signed bit is 1: Number is negative.

e.g memory repersentation of char a=7;


Binary equivalent of 7 is 111
For 8 bit we will add 5 zero in the left side i.e 00000111
Memory repersentation:

e.g memory repersentation of char a= -7;


Binary equivalent of 7 is 111
For 8 bit we will add 5 zero in the left side i.e 00000111
Since a is negative number so it will store in the memory in the 2’s complement
format

Memory repersentation:
(7) What is endianness of processor?
Ans:
If the size of data type is more than one byte then endianness decides the
memory repersentation of data type. There are two type of endianness.

Little-endian: The processor which follow the following memory repersentation


of data is known as little-endian processor.

First A will fill then B then C then D then E and so on from right to left.
Example of processor: 8085,8086,8088,80286,80386,p1,p2 etc.
Big-endian: The processor which follow the following memory repersentation of
data is known as big-endian processor.

First A will fill then B then C then D then E from right to left.
Example of processor: Motorola, IBM pc etc.

(8) How int data type is repersented in the memory?


Ans:
int may be signed or unsigned both has different memory repersentation.
1. Memory repersentation 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 which follow little-endian.
Here A is 00000111 and B is 00000000
Memory repersentation :

Note: same memory repersentation will be of : usigned short int a=7;


2. Memory repersentation of: unsigned long int a=8888855555;
It is 32-bit data type and all 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 repersentation :

3.
(a) Memory repersentation of: int a=7 or signed int a=7;
It is 16 bit data type .
15 bit: data bit
1 bit: signed bit
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Here
A is 00000111
B is 00000000
Memory repersentation :

Note: same memory repersentation will be of: short int a=7 or signed short int
a=7;

(b) Memory repersentation of : int a= -7 or signed int a= -7;


It is 16 bit data type .
Binary equivalent of 7 is 111
For 16 bit we will add 13 zero in the left side i.e 00000000 00000111
Since a is negative number so it will first convert in the 2’s comlement format
before stored in the memory.

Memory repersentation :

Note: same memory repersentation will be of : short int a=-7 or signed short int
a=-7;

(4)
(a) Memory repersentation of : long int a=8888855555 or signed long int
a=8888855555;
It is 32 bit data type .
31 bit : data bit
1 bit : signed bit
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 16 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001
00110011
Here
A is 00110011
B is 01010001
C is 11111011
D is 00110100
Memory repersentation :

(b) Memory repersentation of : int a= -8888855555 or signed int a=


-8888855555;
It is 32 bit data type .
Bit no 31 is signed bit.
Binary equivalent of 8888855555 is 110100 11111011 01010001 00110011
For 32 bit we will add 2 zero in the left side i.e 00110100 11111011 01010001
00110011
Since a is negative number so it will first convert in the 2’s comlement format
before stored in the memory.
Memory repersentation :

(8) How float,double data type is repersented in the memory ?


Ans:
Float : It is 32 bit data type.
23 bit : for mantissa
8 bit : for exponent ( including one signed bit of exponent )
1 bit : for signed bit of mantissa

e.g Memory repersentation of float a = -3.3f;


step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… =
1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010011 00110011 001100110 (only first 23 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : stotre 1 in the signed bit (green colour in the figure )
Step 6: Add 127 in the exponent and convert in the binary number form ( since
in 7 bit of exponent except signed bit maximum possible number is 1111111 )
Exponent= 127+1=128
Binary form of 128 is 1000000 0
Store first bit i.e 0 at the 0 th position of exponent. (in figure red colour zero)
Store rest 7 bit at 1 to 7 bit of exponent from right to left (in figure red color 1
to 7)
Step 7: store the 23 bit mantissa at 1 to 23 bit position in as shown in figure
.Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa
as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure
and so on.
In the memory -3.3 is repersente as :

double:
It is 64 bit data type.
52 bit : for mantissa
11 bit : for exponent (including one signed bit of exponent )
1 bit : for signed bit of mantissa

e.g Memory repersentation of double a = -3.3 ;


step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… =
1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010 01100110 01100110 01100110 01100110 01100110 01100110
(only first 52 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : stotre 1 in the signed bit (green colour in the figure )
Step 6: Add 1023 in the exponent and convert in the binary number form
( since in 10 bit of exponent except signed bit maximum possible number is
1111111111 )
Exponent= 1023+1=1024
Binary form of 1024 is 10000000000
Store first 4 bit i.e 0000 at the 0 to 3 position of exponent. (in figure blue
colour digit)
Store rest 7 bit at 4 to 10 bit of exponent from right to left (in figure blue color
4 to 10)
Step 7: store the 52 bit mantissa at 1 to 52 bit position in as shown in figure
.Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa
as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure
and so on.
In the memory -3.3 is repersente as :

(9) What will be output :

void main()
{
float a= -3.3f;
int i;
unsigned char *p=&a;
for(int i=0;i<4;i++)>