C Objective
C Objective
A. 216 – 1
B. 215 – 1
C. 216
D. 215
E. None of these
Answer: Option A
Solution:
An integer is a number with no fractional part; it can be positive, negative or zero. In ordinary usage,
one uses a minus sign to designate a negative integer. However, a computer can only store
information in bits, which can only have the values zero or one. We might expect, therefore, that the
storage of negative integers in a computer might require some special technique. As you might
imagine, an unsigned integer is either positive or zero. Consider a single digit decimal number: In a
single decimal digit, you can write a number between 0 and 9. In two decimal digits, you can write a
number between 0 and 99, and so on. Since nine is equivalent to 101 - 1, 99 is equivalent to 102 - 1,
etc. In n decimal digits, you can write a number between 0 and 10 n - 1. So, analogously, in the binary
number system, An unsigned integer containing n bits can have a value between 0 and 2 n - 1 (which
is 2n different values).
[Link] is the correct value to return to the operating system
upon the successful completion of a program?
A. 1
B. -1
C. 0
E. 2
Answer: Option C
A. start()
B. system()
C. main()
D. printf()
E. getch()
Answer: Option C
A. float
B. real
C. int
D. double
E. char
Answer: Option B
char ch;
int i;
ch = 'G';
i = ch-'A';
printf("%d", i);
A. 5
B. 6
C. 7
D. 8
E. 9
Answer: Option B
Solution:Since the ASCII value of G is 71 and the garbage value if A is 65 and hence the
difference is 6.
A. Examveda
B. Exam_veda
C. Exam veda
D. Both A and B
E. None of these
Answer: Option C
Solution:
No spaces are allowed in the variable names.
A. 0289
B. 1289
C. 713
D. 0713
E. Syntax error
Answer: Option E
Solution:
The prefix 0 in an integer value indicates octal value. In octal value use of 8 and 9 is not
allowed and hence the error.
void main()
{
int i=065, j=65;
printf("%d %d", i, j);
}
A. 53 65
B. 65 65
C. 065 65
D. 053 65
E. Syntax error
Answer: Option A
Solution:
As octal 65 ( 065 ) is equivalent of decimal value 53.
[Link] ASCII value of 'x' is 120, then what is the value of the H,
if
H = ('x' – 'w' ) / 3;
A. 1
B. 2
C. 3
D. 4
E. 0
Answer: Option E
Solution:
Because 'x'-'w' = 120-119. And hence 1/3 results in 0(integer division)
A. Both can occur multiple times, but a declaration must occur first.
C. Both can occur multiple times, but a definition must occur first.
Answer: Option D
22.
A. 6
B. 7
C. 12
D. 24
Answer: Option D
Solution:
The following table provides the details of standard integer types with their storage sizes
and value ranges −
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
23. Property which allows to produce different executable for different platforms in C is
called?
A. File inclusion
B. Selective inclusion
C. Conditional compilation
D. Recursive macros
Answer: Option C
Explanation:
Conditional compilation is the preprocessor facility to produce different executable.
A. Preprocessor directive
B. Inclusion directive
Answer: Option A
Explanation:
None.
25. C preprocessors can have compiler specific features.
A. true
B. false
Answer: Option A
Explanation:
#pragma is compiler specific feature.
26. C preprocessor is conceptually the first step during compilation.
A. true
B. false
Answer: Option A
27. Preprocessor feature that supply line numbers and file names to compiler is called?
A. Selective inclusion
B. macro substitution
C. Concatenation
D. Line control
Answer: Option D
int main()
{
enum {ORANGE = 12, MANGO, BANANA = 11, APPLE};
printf("APPLE = %d\n", APPLE);
}
A. APPLE= 11
B. APPLE= 12
C. APPLE= 23
D. APPLE= 0
Answer: Option B
Explanation:
In enum, the value of constant is defined to the recent assignment from left.
[Link] is the output of this C code?
int main()
{
printf("C programming %s", "Class by\n%s AllIndiaExams", "SUPER");
}
D. Compilation error
Answer: Option C
Explanation:
This program has only one %s within first double quotes, so it does not read the string
“SUPER”.
The %s along with the AllIndiaExams is not read as a format modifier while new line
character prints the new line.
#define a 20
int main()
{
const int a = 50;
printf("a = %d\n", a);
}
A. a = 50
B. a = 20
D. Compilation Error
Answer: Option D
Explanation:
The #define substitutes a with 20 leaving no identifier and hence compilation error.
Complilation Error: expected identifier or ‘(’ before numeric constant
int main()
{
int var = 010;
printf("%d", var);
}
A. 2
B. 8
C. 9
D. 10
Answer: Option B
Explanation:
010 is octal representation of 8.
A. Compiler
B. Preprocessor
C. Linker
D. Assembler
Answer: Option A
int main()
{
const int a;
a = 32;
printf("a is %d", a);
return 0;
}
A. a is 32
D. none
Answer: Option B
Explanation:
Since the constant variable has to be declared and defined at the same time, not doing it
results in an error.
Answer: Option A
Explanation:
Since the constant variable has to be declared and defined at the same time, not doing it
results in an error.
Hence the statement a is false.
void main()
{
int const k = 11;
k++;
printf("k is %d", k);
}
A. k is 12
C. garbage value
Answer: Option D
Explanation:
Constant variable has to be declared and defined at the same time. Trying to change it later
results in error.
36. Comment on the output of this C code?
B. [Link]
C. Runtime Error
D. complilation error
Answer: Option B
37. The format identifier ‘%i’ is also used for _____ data type?
A. char
B. int
C. float
D. double
Answer: Option B
Explanation:
Both %d and %i can be used as a format identifier for int data type.
38. Which data type is most suitable for storing a number 65000 in a 32-bit system?
A. short
B. int
C. long
D. double
Answer: Option A
Explanation:
65000 comes in the range of short (16-bit) which occupies the least memory.
A. 4 Bytes
B. 8 Bytes
D. Cannot be determined
Answer: Option C
Explanation:
The size of the data types depend on the system.
int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
A. 128
B. -128
Answer: Option B
Explanation:
signed char will be a negative number.
Output:
$ cc pgm2.c
$ [Link]
-128
42. What is short int in C programming?
A. Basic datatype of C
B. Qualifier
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;
}
C. Compiler error
Answer: Option A
Explanation:
Size of any type of pointer is 4 on a 32-bit machine.
Output:
$ cc pgm6.c
$ [Link]
p and q are 4 and 4
Answer: Option C
Explanation:
char has lesser bytes than int and int has lesser bytes than double in any system
A. int
B. struct
C. float
D. double
Answer: Option B
Explanation:
Since the size of the structure depends on its fields, it has a variable size.
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
A. a
C. a.0000000
D. 97.000000
Answer: Option D
Explanation:
Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
$ cc pgm8.c
$ [Link]
97.000000
47. What is the output of this C code?
int main()
{
int i = -5;
int k = i %4;
printf("%d\n", k);
}
B. -1
C. 1
D. None
Answer: Option B
int main()
{
int i = 5;
int l = i / -4;
int k = i % -4;
printf("%d %d\n", l, k);
return 0;
}
B. -1 1
C. 1 -1
int main()
{
int i = 7;
i = i / 4;
printf("%d\n", i);
return 0;
}
B. 1
C. 3
void main()
{
int x = 4 *5 / 2 + 9;
}
A. 6.75
B. 1.85
C. 19
D. 3
Answer: Option C
void main()
{
int x = 4.3 % 2;
printf("Value of x is %d", x);
}
A. Value of x is 1.3
B. Value of x is 2
C. Value of x is 0.3
void main()
{
int a = 5;
int b = ++a + a++ + --a;
printf("Value of b is %d", b);
}
A. Value of x is 16
B. Value of x is 21
C. Value of x is 15
D. Undefined behaviour
Answer: Option D
A. %, *, /, +, -
B. %, +, /, *, -
C. +, -, %, *, /
D. %, +, -, *, /
Answer: Option A
A. a *= 20;
B. a /= 30;
C. a %= 40;
D. a != 50;
Answer: Option D
55. Which of the following data type will throw an error on modulus operation(%)?
A. char
B. short
C. float
D. int
Answer: Option C
void main()
{
int x = 0;
if (x = 0)
printf("Its zero\n");
else
printf("Its not zero\n");
}
B. Its zero
D. None
Answer: Option A
8. What is an array?
A. An array is a collection of variables that are of the dissimilar data type.
B. An array is a collection of variables that are of the same data type.
C. An array is not a collection of variables that are of the same data type.
D. None of the above.
Answer : B
11. What is the right way to access value of structure variable book{ price, page }?
A. printf("%d%d", [Link], [Link]);
B. printf("%d%d", [Link], [Link]);
C. printf("%d%d", price::book, page::book);
D. printf("%d%d", price->book, page->book);
Answer : A
26. The _______ memory allocation function modifies the previous allocated space.
A. calloc
B. free
C. malloc
D. realloc
Answer : D
27. The "C" language is
A. Context free language
B. Context sensitive language
C. Regular language
D. None of the above
Answer : A
36. What will be output if you will compile and execute the following c code?
struct marks{
int p:3;
int c:3;
int m:2;
};
void main(){
struct marks s={2,-6,5};
printf("%d %d %d",s.p,s.c,s.m);
}
(a) 2 -6 5
(b) 2 -6 1
(c) 2 2 1
(d) Compiler error
(e) None of these
Ans: c
50. main()
{
struct
{
int i;
}xyz;
(*xyz)->i=10;
printf("%d",xyz.i);
}
What is the output of this program?
a) program will not compile
b) 10
c) god only knows
d) address of I
Ans: b
[Link] will happen if in a C program you assign a value to an array element whose
subscript exceeds the size of array?
A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash if some important data gets overwritten.
D. The array size would appropriately grow.
Ans: C
53. What will be the value of `a` after the following code is executed
#define square(x) x*x
a = square(2+3)
a) 25
b) 13
c) 11
d) 10
Ans: c
54. #include
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}
int main()
{
func();
func();
return 0;
}
What will the code above print when it is executed?
a)
1 -- 1
1 -- 1
b)
1 -- 1
2 -- 1
c)
1 -- 1
2 -- 2
d)
1 -- 1
1 -- 2
Ans: d
57. int i = 4;
switch (i)
{
default: ;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
What will the output of the sample code above be?
a) i = 5
b) i = 8
c) i = 9
d) i = 10
Ans: a
58. What will be output if you will compile and execute the following c code?
void main()
{
if(printf("cquestionbank"))
printf("I know c");
else
printf("I know c++");
}
(a) I know c
(b) I know c++
(c) cquestionbankI know c
(d) cquestionbankI know c++
(e) Compiler error
Answer: (c)
[Link] will be output if you will compile and execute the following c code?
#define call(x) #x
void main(){
printf("%s",call(c/c++));
}
(a)c
(b)c++
(c)#c/c++
(d)c/c++
(e)Compiler error
Answer: (d)
60. What will be output if you will compile and execute the following c code?
#define message "union is\
power of c"
void main()
{
clrscr();
printf("%s",message);
getch();
}
(a) union is power of c
(b) union is power of c
(c) union is Power of c
(d) Compiler error
(e) None of these
Answer: (b)
61. What will be output if you will compile and execute the following c code?
void main(){
int a=25;
clrscr();
printf("%o %x",a,a);
getch();
}
(a) 25 25
(b) 025 0x25
(c) 12 42
(d) 31 19
(e) None of these
Answer: (d)
62. What will be output if you will compile and execute the following c code?
void main()
{
int i=0;
if(i==0){
i=((5,(i=3)),i=1);
printf("%d",i);
}
else
printf("equal");
}
(a) 5
(b) 3
(c) 1
(d) equal
(e) None of above
Answer: (c)
[Link] will be output if you will compile and execute the following c code?
int extern x;
void main()
printf("%d",x);
x=2;
getch();
}
int x=23;
(a) 0
(b) 2
(c) 23
(d) Compiler error
(e) None of these
Answer: (c)
[Link] will be output if you will compile and execute the following c code?
void main(){
int a,b;
a=1,3,15;
b=(2,4,6);
clrscr();
printf("%d ",a+b);
getch();
}
(a) 3
(b) 21
(c) 17
(d) 7
(e) Compiler error
Answer: (d)
65. What will be output if you will compile and execute the following c code?
void main(){
static main;
int x;
x=call(main);
clrscr();
printf("%d ",x);
getch();
}
int call(int address){
address++;
return address;
}
(a) 0
(b) 1
(c) Garbage value
(d) Compiler error
(e) None of these
Answer: (b)
66. What will be output if you will compile and execute the following c code?
#include "string.h"
void main(){
clrscr();
printf("%d %d",sizeof("string"),strlen("string"));
getch();
}
(a) 6 6
(b) 7 7
(c) 6 7
(d) 7 6
(e) None of these
Answer: (d)
76. A variable in c
a) must have a valid data type
b) can't have a name same as keyword
c) must have a name starting with a character
d) All of above
Answer: D