C Questions
C Questions
4. Pointers are of
a) integer data type
b) character data type
c) unsigned integer data types
d) None of these <ANS>
5. Which of following is a keyword used for a storage class:
a) printf
b) external
c) auto <ANS>
d) scanf
6. When a 'C' function call is made, the order in which parameters are passed to
the function are pushed into the stack is
a) left to right
b) right to left <ANS>
c) bigger variables are moved first than the smaller variables
d) smaller variables are moved first than the bigger ones
e) none of the above
a) 1 2 3 4 5 6 7 8 9
b) 1 2 3 10
c) 4 5 6 7 8 9 10 <ANS>
d) 4 5 6 7 8 9
a) Only a
b) Only b
c) Both a and b <ANS>
d) None of these options
12. #define MAX_NUM 15
Referring to the sample above, what is MAX_NUM?
a) MAX_NUM is an integer variable.
b) MAX_NUM is a linker constant.
c) MAX_NUM is a precompiler constant.
d) MAX_NUM is a preprocessor macro. <ANS>
e) MAX_NUM is an integer constant.
13. int x = 2 * 3 + 4 * 5;
What value will x contain in the sample code above?
a) 22
b) 26 <ANS>
c) 46
d) 50
e) 70
14. C is which kind of language?
a) Machine
b) Procedural <ANS>
c) Assembly
d) Object-Oriented
15.
int x = 0;
for (x=1; x<4; x++);
printf("x=%d\n", x);
What will be printed when the sample code above is executed?
a) x=0
b) x=1
c) x=4 <ANS>
d) x=5
16.
int x = 3;
if( x == 2 );
x = 0;
if( x == 3 )
x++;
else x += 2;
What value will x contain when the sample code above is executed?
a) 1
b) 2 <ANS>
c) 3
d) 4
e) 5
17.
char *ptr;
char myString[] = "abcdefg";
ptr = myString;
ptr += 5;
What string does ptr point to in the sample code above?
a) fg <ANS>
b) efg
c) defg
d) None of the above
18.
double x = -3.5, y = 3.5;
printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) );
printf( "%.0f : %.0f\n", floor( x ), floor( y ) );
What will the code above print when executed?
a) -3 : 4
-4 : 3 <ANS>
b) -4 : 4
-3 : 3
c) -4 : 3
-4 : 3
d) -4 : 3
-3 : 4
e) -3 : 3
-4 : 4
19.
x = 3, counter = 0;
while ((x-1))
{
++counter;
x--;
}
a) 0
b) 2 <ANS>
c) 3
d) 4
20. Which one of the following will read a character from the keyboard and will
store it in the variable c?
a) c = getc();
b) getc( &c );
c) c = getchar( stdin );
d) getchar( &c )
e) c = getchar(); <ANS>
21. Which one of the following C operators is right associative?
a) = <ANS>
b) ,
c) []
d) ^
e) ->
22. What does the "auto" specifier do?
a) It automatically initializes a variable to 0;.
b) It indicates that a variable's memory will automatically be preserved. <ANS>
c) It automatically increments the variable when used.
d) It automatically initializes a variable to NULL.
e) It indicates that a variable's memory space is allocated upon entry into the
block.
23. How do you include a system header file called sysheader.h in a C source fil
e?
a) #include <sysheader.h> <ANS>
b) #incl "sysheader.h"
c) #includefile <sysheader>
d) #include sysheader.h
e) #incl <sysheader.h>
24. Which one of the following printf() format specifiers indicates to print a d
ouble value in decimal notation, left aligned in a 30-character field, to four (
4) digits of precision?
a) %-30.4e
b) %4.30e
c) %-4.30f
d) %-30.4f <ANS>
e) %#30.4f
25. int y[4] = {6, 7, 8, 9};
int *ptr = y + 2;
printf("%d\n", ptr[ 1 ] );
What is printed when the sample code above is executed?
a) 6
b) 7
c) 8
d) 9 <ANS>
e) The code will not compile.
26. int i = 4;
int x = 6;
double z;
z = x / i;
printf("z=%.2f\n", z);
a) z=0.00
b) z=1.00 <ANS>
c) z=1.50
d) z=2.00
e) z=NULL
31.
#include <stdio.h>
void func()
{
int x = 0;
static int y = 0;
x++; y++;
printf( "%d -- %d\n", x, y );
}
int main()
{
func();
func();
return 0;
}
a)
1 -- 1
1 -- 1
b)
1 -- 1
2 -- 1
c)
1 -- 0
1 -- 0
d)
1 -- 1
1 -- 2 <ANS>
32.
c = getchar();
What is the proper declaration for the variable c in the code above?
a) char *c;
b) unsigned int c;
c) int c;
d) unsigned char c;
e) char c; <ANS>