[Link].
com
Question And Answer
Q.1 What will be output when you will execute following c code?
co
e.
in
nl
A. 0 0
B. 65536 -10
C. 0 65536
D. Compilation error
#include < stdio.h >
int main()
{
signed x;
unsigned y;
x = 10 +- 10u + 10u +- 10;
y = x;
if(x==y)
printf("%d %d",x,y);
else if(x!=y)
printf("%u %u",x,y);
return 0;
}
w
w
.a
p
tio
ANSWER : Option A 0 0
SOLUTION :
Turbo C++ 3.0: 0 0
Turbo C ++4.5: 0 0
Linux GCC: 0 0
Visual C++: 0 0
Consider on the expression:
x = 10 +- 10u + 10u +- 10;
10: It is signed integer constant.
10u: It is unsigned integer constant.
X: It is signed integer variable.
In any binary operation of dissimilar data type for example: a + b
Lower data type operand always automatically type casted into the
operand of higher data type before performing the operation
and result will be higher data type.
As we know operators enjoy
higher precedence than binary operators. So our expression is:
x = 10 + (-10u) + 10u + (-10);
= 10 + -10 + 10 + (-10);
=0
Note: Signed is higher data type than unsigned int.
So, Corresponding signed value of unsigned 10u is +10
Q.2 Which data type is most suitable for storing a number 65000 in a 32-bit system?
A. short
[Link]
Page 1
[Link]
Question And Answer
B. int
C. long
D. double
ANSWER : Option A short
SOLUTION :
65000 comes in the range of short(16-bit)
which occupies the least memory.
co
e.
in
tio
nl
#include < stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf("equal");
else
printf("not equal");
}
Q.3 Comment on the output of following C code?
w
w
.a
p
A. equal
B. not equal
C. Output depends on compiler
D. None of the mentioned
ANSWER : Option a equal
SOLUTION :
0.1f results in 0.1 to be stored in
floating point representations.
Output:
$ cc pgm5.c
$ [Link]
equal
Q.4 What is the output of this C code (on a 32-bit machine)?
#include< stdio.h>
int main()
{
int x = 10000;
double y = 56;
int *p = &x;
double *q = &y;
printf("p and q are %d
and %d",sizeof(p), sizeof(q));
return 0;
[Link]
Page 2
[Link]
Question And Answer
}
A. p and q are 4 and 4
B. p and q are 4 and 8
C. Compile time error
D. p and q are 2 and 8
co
ANSWER : Option A p and q are 4 and 4
SOLUTION :
Size of any type of pointer is 4 on a 32 bit machine,
Output:
$ cc pgm6.c
$ [Link]
nl
in
e.
Q.5 The format specifier '%' is also used for _____ data type?
A. char
B. int
C. float
D. double
.a
p
tio
ANSWER : Option B int
SOLUTION :
Both %d and %i can be used as a format specifier for int data type.
w
w
Q.6 What is short int in C programming?
#include < stdio.h >
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal
");
else
printf("not equal
");
}
A. equal
B. not equal
C. Output depends on compiler
D. None of the mentioned
ANSWER : Option B not equal.
SOLUTION :
0.1 by default is of type double which
has different representation than float
[Link]
Page 3
[Link]
Question And Answer
resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ [Link]
not equal
tio
nl
in
e.
co
ANSWER : Option D All of the mentioned
SOLUTION :
typedef and struct are used to define
user-defined data types.
Enum,typedef,struct are user defined data
types.
Q.7 Which of the following is a User-defined data type?
A. typedef int Boolean;
B. typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
C. struct {char name[10], int age};
D. All of the mentioned
w
w
.a
p
Q.8 Which of the following is not modifier of data type in c?
A. extern
B. huge
C. register
D. All of these are modifiers of data type
ANSWER : Option D All of these are modifiers of data type
SOLUTION :
Available Modifiers in C are
1. signed
2. unsigned
3. long
4. short
Q.9 Which is correct with respect to size of the datatypes?
A. char > int > float
B. int > char > float
C. char < int < double
D. double > char > int
ANSWER : Option C char < int < double.
SOLUTION :
char has lesser bytes than int and
int has lesser bytes than double in any system
Char is 1 byte,int is 2 byte,double more than them.
[Link]
Page 4
[Link]
Question And Answer
Q.10 What is the output of following C code?
#include< stdio.h>
int main()
{
char chr;
chr = 128;
printf("%d", chr);
return 0;
}
co
A. 128
B. -128
C. Depends on the compiler
D. None mentioned of the
in
e.
ANSWER : Option D Depends on the compiler.
SOLUTION :
signed char will be a negative number.
w
w
.a
p
tio
nl
Output:
$ cc pgm2.c
$ [Link]
-128
Character has -128 to 127 range so -128
becomes in roundof.
Q.11 What is the output of the following C code(on a 64 bit machine)?
#include < stdio.h >
union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf("%d", sizeof(s));
return 0;
}
A. 8
B. 5
C. 9
D. 4
ANSWER : Option D 4
SOLUTION :
[Link]
Page 5
[Link]
Question And Answer
co
Q.12 What is the size of an int data type?
A. 4 Bytes
B. 8 Bytes
C. Depends on the system/compiler
D. cannot be determined
Since the size of a union is the size of its maximum datatype,
here int is the largest hence 4.
Output:
$ cc pgm7.c
$ [Link]
4
nl
in
e.
ANSWER : Option C Depends on the system/compiler.
SOLUTION :
The size of the data types depend on the system.
There are different operating systems
16bit, 32bit, 64bit.
w
w
.a
p
tio
Q.13 Which of the datatypes have size that is variable?
A. int
B. struct
C. float
D. double
ANSWER : Option B struct
SOLUTION :
Since the size of the structure depends on its fields,
it has a variable size. Struct is a user defined data type .
It does not contain fixed size.
Depend on there definition size may be changed.
Q.14 What will be output when you will execute
following c code?
#include < stdio.h >
int main()
{
printf("%d",sizeof(6.5));
printf("%d",sizeof(90000));
printf("%d",sizeof('A'));
return 0;
}
A. 8 2 1
[Link]
Page 6
[Link]
Question And Answer
B. 4 4 1
C. 8 4 1
D. 8 4 2
ANSWER : Option D 8 4 2
SOLUTION :
Turbo C++ 3.0: 8 4 2
Turbo C ++4.5: 8 4 2
Linux GCC: 8 4 4
Visual C++: 8 4 4
in
e.
co
By default data type of numeric constants is:
6.5 : double
90000: long int
'A': char
In C size of data type varies from compiler to compiler.
In TURBO C 3.0 (16 bit compilers) size of:
double is 8 byte
.a
p
tio
nl
Character constant is 2 byte (size of char data type is one byte)
In TURBO C 4.5 or Linux GCC compilers (32 bit compilers) size of:
double is 8 byte
long int is 8 byte
Character constant is 2 byte
w
w
Long int is 4 byte
[Link]
Page 7