You are on page 1of 77

What will be the output of the following C program segment?

char inchar = 'A';


switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
A) No choice
B) Choice A
C) Choice A
Choice B No choice
D) Program gives no output as it is erroneous
ANSWER: C
Consider the following C function definition:
int Trial (int a, int b, int c)
{
if ((a > = b) && (c < b)) return b;
else if (a > = b) return Trial (a,c,b);
else return Trial (b,a,c);
}
The function Trial:
A) Finds the maximum of a, b, and c
B) Finds the minimum of a, b and c
C) Finds the middle number of a, b, c
D) None of the above
ANSWER: C
The value of j at the end of the execution of the following C program.
int incr (int i)
{
static int count = 0;
count = count + i;
return (count);
}
main ()
{
int i,j;
for (i = 0; i <=4; i++)
j = incr(i);
}
A) 10
B) 4
C) 6
D) 7
ANSWER: A
Consider the following declaration of a two-dimensional array in C:
char a[100][100];
Assuming that the main memory is byte-addressable and that the array is
stored starting from memory address 0, the address of a[40][50] is
A) 4040
B) 4050
C) 5040
D) 5050
ANSWER: B
Consider the following C-program:
void foo(int n, int sum)
{
int k = 0, j = 0;
if (n == 0) return;
k = n % 10; j = n / 10;
sum = sum + k;
foo (j, sum);
printf ("%d,", k);
}
int main ()
{
int a = 2048, sum = 0;
foo (a, sum);
printf ("%d\n", sum);
getchar();
}
What does the above program print?
A) 8, 4, 0, 2, 14
B) 8, 4, 0, 2, 0
C) 2, 0, 4, 8, 14
D) 2, 0, 4, 8, 0
ANSWER: D
Consider the following C function:
int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
A) 5
B) 6
C) 7
D) 8
ANSWER: C
Consider the following C program
main()
{
int x, y, m, n;
scanf ("%d %d", &x, &y);
/* x > 0 and y > 0 */
m = x; n = y;
while (m != n)
{
if(m>n)
m = m - n;
else
n = n - m;
}
printf("%d", n);
}
The program computes
A) x + y using repeated subtraction
B) x mod y using repeated subtraction
C) the greatest common divisor of x & y
D) the least common multiple of x & y
ANSWER: C
Consider the following C-program:
double foo (double); /* Line 1 */
int main () {
double da, db;
// input da
db = foo (da);
}
double foo (double a) {
return a;
}
The above code compiled without any error or warning. If Line 1 is delet
ed, the above code will show:
A) no compile warning or error
B) some compiler-warnings not leading to unintended results
C) some compiler-warnings due to type-mismatch eventually leading to uninte
nded results
D) compiler errors
ANSWER: D
Consider line number 3 of the following C-program.
int main ( ) { /* Line 1 */
int i, n; /* Line 2 */
fro (i =0, i<n, i++); /* Line 3 */
}
Identify the compilers response about this line while creating the object
-module:
A) No compilation error
B) Only a lexical error
C) Only syntactic errors
D) Both lexical and syntactic errors
ANSWER: C
Consider these two functions and two statements S1 and S2 about them.
int work1(int *a, int i, int j)
{
int x = a[i+2];
a[j] = x+1;
return a[i+2] 3;
}
int work2(int *a, int i, int j)
{
int t1 = i+2;
int t2 = a[t1];
a[j] = t2+1;
return t2 3;
}
S1: The transformation from work1 to work2 is valid, i.e., for any progr
am state and input arguments, work2 will compute the same output and
have the same effect on program state as work1
S2: All the transformations applied to work1 to get work2 will always im
prove the performance (i.e reduce CPU time) of work2 compared to work1
A) S1 is false and S2 is false
B) S1 is false and S2 is true
C) S1 is true and S2 is false
D) S1 is true and S2 is true
ANSWER: D
What is (void*)0?
A) Representation of NULL pointer
B) Representation of void pointer
C) Error
D) None of above
ANSWER: A
Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);
A) char p = *malloc(100);
B) char *p = (char) malloc(100);
C) char *p = (char*)malloc(100);
D) char *p = (char *)(malloc*)(100);
ANSWER: C
In which header file is the NULL macro defined?
A) stdio.h
B) stddef.h
C) stdio.h and stddef.h
D) math.h
ANSWER: C
How many bytes are occupied by near, far and huge pointers (DOS)?
A) near=2 far=4 huge=4
B) near=4 far=8 huge=8
C) near=2 far=4 huge=8
D) near=4 far=4 huge=8
ANSWER: A
If a variable is a pointer to a structure, then which of the following o
perator is used to access data members of the structure through the poin
ter variable?
A) .
B) &
C) *
D) ->
ANSWER: D
In a file contains the line "I am a boy\r\n" then on reading this line i
nto the array str using fgets(). What will str contain?
A) "I am a boy\r\n\0"
B) "I am a boy\r\0"
C) "I am a boy\n\0"
D) "I am a boy"
ANSWER: C
What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
A) open "source.txt" in binary mode for reading
B) open "source.txt" in binary mode for reading and writing
C) Create a new file "source.txt" for reading and writing
D) None of above
ANSWER: A
What does fp point to in the program ?
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
return 0;
}
A) The first character in the file
B) A structure which contains a char pointer which points to the first char
acter of a file.
C) The name of the file.
D) The last character in the file.
ANSWER: B
Which of the following operations can be performed on the file "NOTES.TX
T" using the below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");
A) Reading
B) Writing
C) Appending
D) Read and Write
ANSWER: D
To print out a and b given below, which of the following printf() statem
ent will you use?
#include<stdio.h>
float a=3.14;
double b=3.14;
A) printf("%f %lf", a, b);
B) printf("%Lf %f", a, b);
C) printf("%Lf %Lf", a, b);
D) printf("%f %Lf", a, b);
ANSWER: A
Which files will get closed through the fclose() in the following progra
m?
#include<stdio.h>
int main()
{
FILE *fs, *ft, *fp;
fp = fopen("A.C", "r");
fs = fopen("B.C", "r");
ft = fopen("C.C", "r");
fclose(fp, fs, ft);
return 0;
}
A) "A.C" "B.C" "C.C"
B) "B.C" "C.C"
C) "A.C"
D) Error in fclose()
ANSWER: D
On executing the below program what will be the contents of 'target.txt'
file if the source file contains a line "To err is human"?
#include<stdio.h>
int main()
{
int i, fss;
char ch, source[20] = "source.txt", target[20]="target.txt", t;
FILE *fs, *ft;
fs = fopen(source, "r");
ft = fopen(target, "w");
while(1)
{
ch=getc(fs);
if(ch==EOF)
break;
else
{
fseek(fs, 4L, SEEK_CUR);
fputc(ch, ft);
}
}
return 0;
}
A) r n
B) Trh
C) err
D) None of above
ANSWER: B
To scan a and b given below, which of the following scanf() statement wi
ll you use?
#include<stdio.h>
float a;
double b;
A) scanf("%f %f", &a, &b);
B) scanf("%Lf %Lf", &a, &b);
C) scanf("%f %Lf", &a, &b);
D) scanf("%f %lf", &a, &b);
ANSWER: D
Out of fgets() and gets() which function is safe to use?
A) gets()
B) fgets()
c) puts()
D) fputs()
ANSWER: B
Consider the following program and what will be content of t?
#include<stdio.h>
int main()
{
FILE *fp;
int t;
fp = fopen("DUMMY.C", "w");
t = fileno(fp);
printf("%d\n", t);
return 0;
}
A) size of "DUMMY.C" file
B) The handle associated with "DUMMY.C" file
C) Garbage value
D) Error in fileno()
ANSWER: B
The number of tokens in the following C statement.
printf("i = %d, &i = %x", i, &i); is
A) 3
B) 26
C) 10
D) 21
ANSWER: C
Consider the following C function:
int f(int n)
{
static int r = 0;
if (n <= 0) return 1;
if (n > 3)
{
r = n;
return f(n-2)+2;
}
return f(n-1)+r;
}
What is the value of f(5) ?
A) 5
B) 7
C) 9
D) 18
ANSWER: D
Common data Questions (13 & 14)
Consider the following recursive C function that takes two arguments
unsigned int foo(unsigned int n, unsigned int r) {
if (n > 0) return (n%r + foo (n/r, r ));
else return 0;
}
What is the return value of the function foo when it is called as foo(34
5, 10) ?
A) 345
B) 12
C) 5
D) 3
ANSWER: B
What is the return value of the function foo when it is called as foo(51
3, 2)?
A) 9
B) 8
C) 5
D) 2
ANSWER: D
Choose the correct option to fill ?1 and ?2 so that the program below pr
ints an input string in reverse order. Assume that the input string is termin
ated by a newline character.
void reverse(void)
{
int c;
if (?1) reverse() ;
?2
}
main()
{
printf ("Enter Text ") ; printf ("\n") ;
reverse(); printf ("\n") ;
}
A) ?1 is (getchar() != '\n')
?2 is getchar(c);
B) ?1 is (c = getchar() ) != '\n')
?2 is getchar(c);
C) ?1 is (c != \n)
?2 is putchar(c);
D) ?1 is ((c = getchar()) != '\n')
?2 is putchar(c);
ANSWER: D
The following C declaration
struct node
{
int i;
float j;
};
struct node *s[10] ;
define s to be
A) An array, each element of which is a pointer to a structure of type node
B) A structure of 2 fields, each field being a pointer to an array of 10 el
ements
C) A structure of 3 fields: an integer, a float, and an array of 10 element
s
D) An array, each element of which is a structure of type node.
ANSWER: A
The most appropriate matching for the following pairs
X: m=malloc(5); m= NULL; 1: using dangling pointers
Y: free(n); n->value=5; 2: using uninitialized pointers
Z: char *p; *p = a; 3: lost memory
is:
A) X1 Y3 Z-2
B) X2 Y1 Z-3
C) X3 Y2 Z-1
D) X3 Y1 Z-2
ANSWER: D
Consider the following C declaration
struct {
short s [5]
union {
float y;
long z;
}u;
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4
bytes and 8 bytes, respectively. The memory requirement for variable
t, ignoring alignment considerations, is
A) 22 bytes
B) 14 bytes
C) 18 bytes
D) 10 bytes
ANSWER: C
Assume the following C variable declaration
int *A [10], B[10][10];
Of the following expressions
I A[2]
II A[2][3]
III B[1]
IV B[2][3]
which will not give compile-time errors if used as left hand sides of as
signment statements in a C program?
A) I, II, and IV only
B) II, III, and IV only
C) II and IV only
D) IV only
ANSWER: A
Consider the following C function
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
In order to exchange the values of two variables x and y.
A) call swap (x, y)
B) call swap (&x, &y)
C) swap (x,y) cannot be used as it does not return any value
D) swap (x,y) cannot be used as the parameters are passed by value
ANSWER: D
What does the following C-statement declare?
int ( * f) (int * ) ;
A) A function that takes an integer pointer as argument and returns an inte
ger
B) A function that takes an integer as argument and returns an integer poin
ter
C) A pointer to a function that takes an integer pointer as argument and re
turns an integer.
D) A function that takes an integer pointer as argument and returns a funct
ion pointer
ANSWER: C
What does the following program print?
#include<stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d \n", i, j);
getchar();
return 0;
}
A) 2 2
B) 2 1
C) 0 1
D) 0 2
ANSWER: D
What does the following fragment of C-program print?
char c[] = "GATE2011";
char *p =c;
printf("%s", p + p[3] - p[1]);
A) GATE2011
B) E2011
C) 2011
D) 011
ANSWER: C
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length i];
printf("%s",p);
The output of the program is
A) gnirts
B) gnirt
C) string
D) no output is printed
ANSWER: D
Common Data Question for 25 & 26
Consider the following C program
int a, b, c = 0;
void prtFun (void);
int main ()
{
static int a = 1; /* line 1 */
prtFun();
a += 1;
prtFun();
printf ( "\n %d %d " , a, b) ;
}
void prtFun (void)
{
static int a = 2; /* line 2 */
int b = 1;
a += ++b;
printf (" \n %d %d " , a, b);
}
What output will be generated by the given code segment?
A) 3 1
4 1
4 2
B) 4 2
6 1
6 1
C) 4 2
6 2
2 0
D) 3 1
5 2
5 2
ANSWER: C
What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
A) 3 1
4 1
4 2
B) 4 2
6 1
6 1
C) 4 2
6 2
2 0
D) 4 2
4 2
2 0
ANSWER: D
What is printed by the following C program?
int f(int x, int *py, int **ppz)
{
int y, z;
**ppz += 1;
z = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}
void main()
{
int c, *b, **a;
c = 4;
b = &c;
a = &b;
printf( "%d", f(c,b,a));
getchar();
}
A) 18
B) 19
C) 21
D) 22
ANSWER: B
What does the following fragment of C program print?
char c[] = "GATE2011";
char *p = c;
printf("%s", p + p[3] - p[1]);
A) GATE2011
B) E2011
C) 2011
D) 011
ANSWER: C
The smallest element of an array's index is called its
A) Lower bound.
B) Upper bound.
C) Range.
D) Extraction.
ANSWER: A
O(N)(linear time) is better than O(1) constant time.
A) True
B) False
ANSWER: B
For 'C' programming language
A) Constant expressions are evaluated at compile
B) String constants can be concatenated at compile time
C) Size of array should be known at compile time
D) All of these
ANSWER: D
What is the maximun number of dimensions an array in C may have?
A) Two
B) Eight
C) Twenty
D) Theoratically no limit. The only practical limits are memory size and co
mpilers
ANSWER: D
If x is an array of interger, then the value of &x[i] is same as
A) &x[i-1]+sizeof(int)
B) x+sizeof(int)*i
C) x+i
D) none of these
ANSWER: C
If S is an array of 80 characters, then the value assigned to S through
the statement scanf("%s",S) with input 1 2 3 4 5 would be
A) "12345"
B) nothing since 12345 is an integer
C) S is an illegal name for string
D) %s cannot be used for reading in values of S
ANSWER: A
Size of the array need not be specified, when
A) Initialization is a part of definition
B) It is a declaratrion
C) It is a formal parameter
D) All of these
ANSWER: D
A one dimensional array A has indices 1....75.Each element is a string a
nd takes up three memory words. The array is stored starting at location 1120
decimal. The starting address of A[49] is
A) 1167
B) 1164
C) 1264
D) 1169
ANSWER: C
Minimum number of interchange needed to convert the array 89,19,40,14,17
,12,10,2,5,7,11,6,9,70, into a heap with the maximum element at the root is
A) 0
B) 1
C) 2
D) 3
ANSWER: C
Which of the following is an illegal array definition?
A) Type COLOGNE:(LIME,PINE,MUSK,MENTHOL); var a:array[COLOGNE]of REAL;
B) var a:array[REAL]of REAL;
C) var a:array['A'..'Z']of REAL;
D) var a:array[BOOLEAN]of REAL;
ANSWER: B
#include<stdio.h>
#include<stdarg.h>
void fun1(int num, ...);
void fun2(int num, ...);
int main()
{
fun1(1, "Apple", "Boys", "Cats", "Dogs");
fun2(2, 12, 13, 14);
return 0;
}
void fun1(int num, ...)
{
char *str;
va_list ptr;
va_start(ptr, num);
str = va_arg(ptr, char *);
printf("%s ", str);
}
void fun2(int num, ...)
{
va_list ptr;
va_start(ptr, num);
num = va_arg(ptr, int);
printf("%d", num);
}
A) Dogs 12
B) Cats 14
C) Boys 13
D) Apple 12
ANSWER: A
#include<stdio.h>
#include<stdarg.h>
fun(...);
int main()
{
fun(3, 7, -11.2, 0.66);
return 0;
}
fun(...)
{
va_list ptr;
int num;
va_start(ptr, n);
num = va_arg(ptr, int);
printf("%d", num);
}
A) Error: fun() needs return type
B) Error: ptr Lvalue required
C) Error: Invalid declaration of fun(...)
D) No error
ANSWER: C
#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);
int main()
{
display(4, 'A', 'a', 'b', 'c');
return 0;
}
void display(int num, ...)
{
char c; int j;
va_list ptr;
va_start(ptr, num);
for(j=1; j<=num; j++)
{
c = va_arg(ptr, char);
printf("%c", c);
}
}
A) Error: unknown variable ptr
B) Error: Lvalue required for parameter
C) No error and print A a b c
D) No error and print 4 A a b c
ANSWER: C
The value of a resistor creating thermal noise is doubled the noise powe
r generated is therefore
A) Halved
B) Quadrupled
C) Unchanged
D) Doubled
ANSWER: C
De-emphasis circuit is used
A) After modulation
B) Prior to modulation
C) To de-emphasis low frequency component
D) To de-emphasis high frequency component
ANSWER: D
The capacity of a channel is
A) Number of digits used in coding
B) Volume of information it can take
C) Maximum rate of information transmission
D) Bandwidth required for information
ANSWER: C
void main()
{
int const *p=5;
printf("%d"' ++(*p));
}
A) 6
B) 5
c) Garbage value
D) compilier Error
ANSWER: D
main()
{
static int var=5;
printf("%d"'var--);
if(var)
main();
A) 1.55555
B) 54321
C) infinite loop
D) None
ANSWER: B
main()
{
char *p;
printf("%d%d",size of(*p),size of(p));
A) 11
B) 12
C) 21
D) 22
ANSWER: B
main()
{
int c=--2;
printf("c=%d",c);
}
A) 1
B) -2
C) 2
D) Error
ANSWER: B
#define int char
main()
{
inti=65;
printf("size of(i)=%d",size of(i));
}
A) size of(i)=2
B) size(i)=1
C) compiler error
D) None
ANSWER: B
main()
{
char string[]="Helloworld"
display(strings);
}
void diaplay(char*string)
{
printf("%s",string)
}
A) compiler Error
B) Helloworld
C) can't say
D) None
ANSWER: A
#define square(*)***
main()
{
int i;
i=64/squqre(4);
printf("%d",i);
}
A) 4
B) 64
C) 16
D) None
ANSWER: B
#include<stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
A) 50
B) 10
C) compile Error
D) None
ANSWER: A
#define clrscr() 100
main()
{
clrscr();
printf("%d/n");
clrscr();
A) 0
B) 1
C) 100
D) None
ANSWER: C
main()
{
int i=1;j=2;
switch(i)
{
case i:printf("GOOD");break;
case j;printf("BAD");break;
}
}
a) Good
b) Bad
c) GOOD Bad
D) Error
ANSWER: D
main()
{
int i=0;
for(;i++;prntf("%d",i));
printf("%d",i);
}
A) 1
B) 11
C) 12
D) Error
ANSWER: A
main()
{
extern int i;
i=20;
printf("%d",size of(i));
}
A) 20
B) 2
C) compile Error
D) Linear Error
ANSWER: D
main()
{
int i=0;j=0;
if(i&&j++)
printf("%d..%d",i++,j);
printf("%d..%d",i,j);
}
A) 0..1
B) 1..0
C) 0..0
D) 1..1
ANSWER: D
void main()
{
static int i=5;
if(--i)
{
main();
printf("%d",i);
}
}
A) 54321
B) 0000
C) infiniteloop
D) None
ANSWER: B
#include
main()
{
register i=5;
char j[]=("hello");
printf("%s%d",j,i);
}
A) Hello 5
B) Hello garbage value
C) Error
D) None
ANSWER: A
What will be output if you will compile and execute the followin
g c code?
void main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else{
break;
}
}
A) It will print nothing.
B) -3
C) compiler error
D) 1
ANSWER: C
What will be output of the following c program?
#include<stdio.h>
int main(){
int goto=5;
printf("%d",goto);
return 0;
}
A) 5
B) **
C) **
D) Compilation error
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
long int 1a=5l;
printf("%ld",1a);
return 0;
}
A) 5
B) 51
C) 6
D) Compilation error
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
int _=5;
int __=10;
int ___;
___=_+__;
printf("%i",___);
return 0;
}
A) 5
B) 10
C) 15
D) Compilation error
ANSWER: C
#include<stdio.h>
int main(){
int max-val=100;
int min-val=10;
int avg-val;
avg-val = max-val + min-val / 2;
printf("%d",avg-val);
return 0;
}
A) 55
B) 105
C) 60
D) Compilation error
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
int class=150;
int public=25;
int private=30;
class = class >> private - public;
printf("%d",class);
return 0;
}
A) 1
B) 2
C) 4
D) Compilation error
ANSWER: C
What will be output of the following c program?
#include<stdio.h>
int main(){
int abcdefghijklmnopqrstuvwxyz123456789=10;
int abcdefghijklmnopqrstuvwxyz123456=40;
printf("%d",abcdefghijklmnopqrstuvwxyz123456);
return 0;
}
A) 10
B) 40
C) 50
D) Compilation error
main()
{
char string[]="Helloworld"
display(strings);
}
void diaplay(char*string)
{
printf("%s",string)
}
A) compiler Error
B) Helloworld
C) can't say
D) None
ANSWER: A
#define square(*)***
main()
{
int i;
i=64/squqre(4);
printf("%d",i);
}
A) 4
B) 64
C) 16
D) None
ANSWER: B
What will be output if you will compile and execute the following c code
?
void main(){
int a=10;
printf("%d %d %d",a,a++,++a);
}
A) 12 11 11
B) 12 10 10
C) 11 11 12
D) 10 10 12
ANSWER: A
What will be output if you will compile and execute the following c code
?
void main(){
char *str="Hello world";
printf("%d",printf("%s",str));
}
A) 11Hello world
B) 10Hello world
C) Hello world10
D) Hello world11
ANSWER: D
#include<stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
A) 50
B) 10
C) compile Error
D) None
ANSWER: A
#define clrscr() 100
main()
{
clrscr();
printf("%d/n");
clrscr();
A) 0
B) 1
C) 100
D) None
ANSWER: C
What will be output if you will compile and execute the following c code
?
#include "stdio.h"
#include "string.h"
void main(){
char *str=NULL;
strcpy(str,"cquestionbank");
printf("%s",str);
}
A) cquestionbank
B) cquestionbank\0
C) (null)
D) It will print nothing
ANSWER: C
What will be output if you will compile and execute the following c code
?
#include "stdio.h"
#include "string.h"
void main(){
int i=0;
for(;i<=2;)
printf(" %d",++i);
}
A) 0 1 2
B) 0 1 2 3
C) 1 2 3
D) Compiler error
ANSWER: C
main()
{
int i=1;j=2;
switch(i)
{
case i:printf("GOOD");break;
case j;printf("BAD");break;
}
}
A) Good
B) Bad
C) GOOD Bad
D) Error
ANSWER: D
main()
{
int i=0;
for(;i++;prntf("%d",i));
printf("%d",i);
}
A) 1
B) 11
C) 12
D) Error
ANSWER: A
main()
{
extern int i;
i=20;
printf("%d",size of(i));
}
A) 20
B) 2
C) compile Error
D) Linear Error
ANSWER: D
main()
{
int i=0;j=0;
if(i&&j++)
printf("%d..%d",i++,j);
printf("%d..%d",i,j);
}
A) 0..1
B) 1..0
C) 0..0
D) 1..1
ANSWER: D
void main()
{
static int i=5;
if(--i)
{
main();
printf("%d",i);
}
}
A) 54321
B) 0000
C) infiniteloop
D) None
ANSWER: B
What will be output if you will compile and execute the following c code
?
void main(){
int x;
for(x=1;x<=5;x++);
printf("%d",x);
}
A) 4
B) 5
C) 6
D) Compiler error
ANSWER: C
#include
main()
{
register i=5;
char j[]=("hello");
printf("%s%d",j,i);
}
A) Hello 5
B) Hello garbage value
C) Error
D) None
ANSWER: A
main()
{
int i=abc(10);
printf("%d\n",--i);
}
int abc(int i)
{
return(i++);
}
A) 10
B) 9
C) 11
D) None
ANSWER: B
void main()
{
static int i=i++,j=j++,k=k++;
printf("%d%d%d",i,j,k);
}
A) 111
B) 000
C) Garbage value
D) Error
ANSWER: A
#define pnod(a,b) a*b
main()
{
int x=3,y=4;
printf("%d,pnod(x+2,y-1));
}
A) 15
B) 10
C) 12
D) 11
ANSWER: B
main()
{
char p[]="%d\n";
p[1]='c';
printf(p,65);
A) 65
B) C
c) A
D) Error
ANSWER: C
What is the return value of f( p,p) if the value of p is initialized to
5 before the call? Note that the first parameter is passed by reference, where
as the second parameter is passed by value.
int f( int & x, int c)
{
c= c- 1;
If( c== 0) return 1;
X= x+ 1; return f (x,c) * x;
}
A) 3024
B) 6561
C) 55440
D) 161051
ANSWER: C
What will be output if you will compile and execute the following c code
?
void main(){
printf("%d",sizeof(5.2));
}
A) 2
B) 4
C) 8
D) 10
ANSWER: C
What will be the output of the following program ?
#include
void main()
{
int a = 2;
switch(a)
{
case 1:
printf("goodbye");
break;
case 2:continue;
case 3:printf("bye");
}
}
A) error
B) goodbye
C) bye
D) byegoodbye
ANSWER: A
void main(){
double far* p,q;
printf("%d",sizeof(p)+sizeof q);
}
A) 12
B) 8
C) 4
D) 1
ANSWER: A
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
ANSWER: A
long factorial (long x)
{
return x * factorial(x - 1);
}
With what do you replace the ???? to make the function shown above retur
n the correct answer?
A) if (x == 0) return ;
B) return 1;
C) if (x >= 2) return 2;
D) if (x <= 1) return 1;
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
int __SMALL__ = 11;
int y;
y= __SMALL__ < 5;
printf("%d",y);
return 0;
}
A) 11
B) 5
C) 0
D) Compilation error
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
int __BIG__ = 32;
int y;
y= __BIG__ && 8;
printf("%d",y);
return 0;
}
A) 32
B) 8
C) 1
D) Compilation error
ANSWER: C
What will be output of the following c program?
#include<stdio.h>
static num=5;
int num;
extern int num;
int main(){
printf("%d",num);
return 0;
}
A) 5
B) 10
C) 0
D) Compilation error
ANSWER: A
#include<stdio.h>
static num=5;
extern int num;
int main(){
printf("%d",num);
return 0;
}
int num =25;
A) 0
B) 5
C) 25
D) Compilation error
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
static num;
int main(){
printf("%d",num);
return 0;
}
int num =25;
A) 0
B) 1
C) 25
D) Compilation error
ANSWER: C
#define max 5;
void main(){
int i=0;
i=max++;
printf("%d",i++);
}
A) 5
B) 6
C) 7
D) 0
ANSWER: D
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
ANSWER: A
#include<stdio.h>
int xyz=10;
int main(){
int xyz=20;
printf("%d",xyz);
return 0;
}
A) 10
B) 20
C) 30
D) Compilation error
ANSWER: B
#include<stdio.h>
int main(){
int xyz=20;
int xyz;
printf("%d",xyz);
return 0;
}
A) 20
B) 0
C) Garbage
D) Compilation error
ANSWER: D
#include<stdio.h>
int main(){
int xyz=20;{
int xyz=40;
}
printf("%d",xyz);
return 0;
}
A) 20
B) 40
C) 0
D) Compilation error
ANSWER: A
What will be output of the following c program?
#include<stdio.h>
int main(){
int main = 80;
printf("%d",main);
return 0;
}
A) 80
B) 0
C) Garbage value
D) Compilation error
ANSWER: A
#include<stdio.h>
int main(){
struct a{
int a;
};
struct a b={10};
printf("%d",b.a);
return 0;
}
A) 0
B) 10
C) Garbage value
D) Compilation error
ANSWER: B
What will be output of the following c program?
#include<stdio.h>
int main(){
int ABC=10;
printf("%d",abc);
return 0;
}
A) 10
B) 0
C) 5
D) Compilation error
ANSWER: D
#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 -- 11 -- 1
B) 1 -- 12 -- 1
C) 1 -- 12 -- 2
D) 1 -- 11 2
ANSWER: D
What will be output of the following c program?
#include<stdio.h>
int main(){
int printf=12;
printf("%d",printf);
return 0;
}
A) 12
B) 0
C) 5
D) Compilation error
ANSWER: D
What will be the value of `a` after the following code is executed
#define square(x)
x*xa = square(2+3)
A) 25
B) 13
C) 11
D) 0
ANSWER: C
#include<stdio.h>
int main(){
int EOF=12;
printf("%d",EOF);
return 0;
}
A) 12
B) 0
C) 5
D) Compilation error
ANSWER: D
#include
void main()
{
int a = 36, b = 9;
printf("%d",a>>a/b-2);
}
A) 9
B) 7
C) 5
D) none of these
ANSWER: A
What will be the output of the following statements ?
int a = 4, b = 7,c; c = a = = b;
printf("%i",c);
A) 0
B) error
C) 1
D) garbage value
ANSWER: A
What will be the output of the following statements ?
int a = 5, b = 2, c = 10,
i = a>b
void main()
{
printf("hello");
main();
}
A) 1
B) 2
C) infinite number of times
D) none of these
ANSWER: c
What will be the output of the following statements ?
int x[4] = {1,2,3};
printf("%d %d %D",x[3],x[2],x[1]);
A) 03%D
B) 000
C) 032
D) 321
ANSWER: c What will be the output of following code ?
#include<stdio.h>
void main( )
{
char suite =3;
switch(suite)
{
case 1:
printf("ALL QUIZ");
case 2:
printf("All quiz is great");
default:
printf("All quiz contains MCQs");
}
printf("Are you like All quiz ?");
}

A) ALL QUIZ
B) All quiz is great
C) All quiz contains MCQs
D) All quiz is great Are you like Al quiz ?
ANSWER: D
What will be the output of following code ?
void main( )
{
int c=3;
switch(c)
{
case '3':
printf("Hi");
break;
case 3:
printf("Hello");
break;
default:
printf("How r u ?");
}
}


A) Hi
B) Hello
C) How r u ?
D) None of above
ANSWER: B
What will be the output of following program ?
void main( )
{
int 1=3;
switch(i)
{
case 0:
printf("I am here");
case 1+0:
printf("I m in second case");
case 4/2:
printf("I m in third case");
case 8%5:
printf("Good bye");
}
}
A) All case statements will be executed
B) I am here
C) Good bye
D) I am in third case
ANSWER: C
What will be output if you will compile and execute the following c code
?
#include "stdio.h"
#include "string.h"
void main(){
char c='\08';
printf("%d",c);
}
A) 8
B) 8
C) compiler error
D) null
ANSWER: C
What will be the output of following ?
void main( )
{
int suite =1;
switch(suite);
{
case 0:
printf("Its morning time");
case 1:
printf("Its evening time");
}
}
A) Error
B) Its morning time
C) Its evening time
D) None of above
ANSWER: A
What will be output if you will compile and execute the following c code
?
#define call(x,y) x##y
void main(){
int x=5,y=10,xy=20;
printf("%d",xy+call(x,y));
}
A) 35
B) 510
C) 15
D) 40
ANSWER: D
What will be output if you will compile and execute the following c code
?
int * call();
void main(){
int *ptr;
ptr=call();
clrscr();
printf("%d",*ptr);
}
int * call(){
int a=25;
a++;
return &a;
}
A) 25
B) 26
C) Any address
D) Garbage value
ANSWER: D
What will be the output of following program ?
#include<stdio.h>
int main( )
{
int i=2,j=3,k,l;
float a,b;
k = i/j * j;
l = j/i * j;
a = i/j * j;
b = j/i * i;
printf("%d %d%f%f\n",k,l,a,b);
return 0;
}
A) 3, 0, 0, 0
B) 0, 3, 0.000000, 2.000000
C) 0,0,0,0
D) Error
ANSWER: B
What will be the output of following program ?
#incllude<stdio.h>
int main( )
{
int a,b;
a = -3 - - 25;
b = -3 - - (-3);
printf("a=%d b=%d\n",a,b);
return 0;
}
A) a = 22 b = -6
B) a = -6 b = 22
C) a = 3 b = 3
D) No Output
ANSWER: A
What will be the output of following program ?
#include<stdio.h>
int main( )
{
float a=5,b=2;
int c,d;
c =a%d;
d =a/2;
printf("%d\n",d);
return 0;
}
A) 3
B) 2
C) Error
D) None of above
ANSWER: C
What is error in following declaration?
struct outer{
int a;
struct inner{
char c;
};
};
A) Nesting of structure is not allowed in c.
B) It is necessary to initialize the member variable.
C) Inner structure must have name.
D) Outer structure must have name.
ANSWER: C
What will be the output of program ?
#include<stdio.h>
int main( )
{
printf("nn /n/n nn/n");
return 0;
}
A) Nothing
B) nn /n/n nn
C) nn /n/n
D) Error
ANSWER: B
What will be the output of program ?
#include<stdio.h>
int main( )
{
int a,b;
printf("Enter two values of a and b");
scanf("%d%d",&a,&b);
printf("a=%d b=%d"a,b);
return 0;
}
A) a = 0 b = 0
B) a = 1 b = 1
C) Values you entered
D) None of above
ANSWER: C
A character variable can at a time store ?
A) 1 character
B) 8 character
C) 254 character
D) None of above
ANSWER: A
The maximum value that an integer constant can have is ?
A) -32767
B) 32767
C) 1.7014e + 38
D) -1.7014e + 38
ANSWER: B
What will be output if you will compile and execute the following c code
?
void main(){
int array[]={10,20,30,40};
printf("%d",-2[array]);
}
(A) -60
(B) -30
(C) 60
(D) Garbage value
ANSWER: B
Which of the following is false in C ?
A) Keywords cannot be used as variable names
B) Variable names can contain a digit
C) Variable names do not contain a blank space
D) Capital letters can be used in variable names
ANSWER: A
On which if the following operator can % operator NOT be used ?
A) int variable
B) float variable
C) int constant
D) All of above
What is the output of the following code?
#include
void main()
{
int s=0;
while(s++<10)
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
A) 10..10
B) 10..50
C) ERROR
D) 0
ANSWER: C
void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?
A) XAM is printed
B) exam is printed
C) Compiler Error
D) Nothing is printed
ANSWER: C
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
A) 11
B) 7
C) 5
D) 9
ANSWER: A
The minimum number of temporary variables needed to swap the contents of
two variables is?
A) 1
B) 2
C) 3
D) 0
ANSWER: D
Consider the function?
find(int x,int y)
{return((x<y)?0:(x-y)):}
Let a,b are two non negative integers.The call(find(a,find(a,b))
A) maximum of a,b
B) positive diff of a,b
C) sum of a,b
D) minimum of a,b
ANSWER: D
Let a,b are two non negative integers.which of the following calls finds
the positive diff of a,b?
A) find(a,b)+find(b,a)
B) find(a,find(a,b))
C) a+find(a,b)
D) b+find(a,b)
ANSWER: A
if an integer needs two bytes of storage then maximum value of an unsign
ed integer is?
A) 2pow16-1
B) 2pow15-1
C) 2pow16
D) 2pow15
ANSWER: A
if an integer needs two bytes of storage then maximum value of an signed
integer is?
A) 2pow16-1
B) 2pow15-1
C) 2pow16
D) 2pow15
ANSWER: B
printf("%d",printf("tim"));?
A) results in a syntax error
B) outputs tim3
C) output garbage
D) prints tim
ANSWER: B
Consider the statement:
putchar(getchar()));
putchar(getchar())); if a,b is the input,output will be
A) an error
B) this can't be the input
C) ab
D) a b
ANSWER: B
printf("%c",100);?
A) prints 100
B) prints the ASCII equivalent of 100
C) prints garbage
D) None
ANSWER: B
What will be the output of the following C program segment?
char inChar = A ;
switch ( inChar ) {
case A : printf (Choice A\ n) ;
case B :
case C : printf (Choice B) ;
case D :
case E :
default : printf ( No Choice ) ; }
A) No Choice
B) Choice A
C) Choice A
Choice B No Choice
D) Program gives no output as it is erroneous
Answer:c
The declaration float f[][3]={{1.0},{2.0},{3.0}}; represents _________.
A) a one-by-three array.
B) a three-by-one array.
C) a three-by-three array.
D) a one-by-one-array.
Answer: C
A char array with the string value aeiou can be initialized as ___________
.
A) char s[]={a,e,i,o,u};
B) char s[]=aeiou;
C) char s[]={a, e,i,o,u,\0};
D) both 1 and 2.
Answer: D
The program execution starts from __________.
A) the function which is first defined.
B) main() function.
C) the function which is last defined.
D) the function other than main().
Answer: B
How many main() functions can be defined in a C program?
A) 1.
B) 2.
C) 3.
D) any number of times.
Answer: A
A function is identified by an open parenthesis following ________.
A) a keyword.
B) an identifier other than keywords.
C) an identifier including keywords.
D) an operator.
Answer: C
A function with no action ________.
A) is an invalid function.
B) produces syntax error.112-C Programming
C) is allowed and is known as dummy function.
D) returns zero.
Answer: C
Parameters are used _________.
A) to return values from the called function.
B) to send values from the calling function.
C) both 1 and 2.
D) to specify the data type of the return value.
Answer: C
The default return data type in function definition is _________.
A) void.
B) int.
C) float.
D) char.
Answer: B
Identify the correct statement.
A) A function can be defined more than once in a program.
B) Function definition cannot appear in any order.
C) Functions cannot be distributed in many files.
D) One function cannot be defined within another function definition.
Answer: D
The parameters in a function call are ________.
A) actual parameters.
B) formal parameters.
C) dummy parameters.
D) optional.
Answer: A
What does the following C-statement declare?
int ( * f) (int * ) ;
A) A function that takes an integer pointer as argument and returns an inte
ger
B) A function that takes an integer as argument and returns an integer poin
ter
C) A pointer to a function that takes an integer pointer as argument and re
turns an integer.
D) A function that takes an integer pointer as argument and returns a funct
ion pointer
ANSWER: C
What does the following program print?
#include<stdio.h>
void f(int *p, int *q)
{
p = q;
*p = 2;
}
int i = 0, j = 1;
int main()
{
f(&i, &j);
printf("%d %d \n", i, j);
getchar();
return 0;
}
A) 2 2
B) 2 1
C) 0 1
D) 0 2
ANSWER: D
What does the following fragment of C-program print?
char c[] = "GATE2011";
char *p =c;
printf("%s", p + p[3] - p[1]);
A) GATE2011
B) E2011
C) 2011
D) 011
ANSWER: C
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length i];
printf("%s",p);
The output of the program is
A) gnirts
B) gnirt
C) string
D) no output is printed
ANSWER: D
Common Data Question for 25 & 26
Consider the following C program
int a, b, c = 0;
void prtFun (void);
int main ()
{
static int a = 1; /* line 1 */
prtFun();
a += 1;
prtFun();
printf ( "\n %d %d " , a, b) ;
}
void prtFun (void)
{
static int a = 2; /* line 2 */
int b = 1;
a += ++b;
printf (" \n %d %d " , a, b);
}
What output will be generated by the given code segment?
A) 3 1
4 1
4 2
B) 4 2
6 1
6 1
C) 4 2
6 2
2 0
D) 3 1
5 2
5 2
ANSWER: C
What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
A) 3 1
4 1
4 2
B) 4 2
6 1
6 1
C) 4 2
6 2
2 0
D) 4 2
4 2
2 0
ANSWER: D
What is printed by the following C program?
int f(int x, int *py, int **ppz)
{
int y, z;
**ppz += 1;
z = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}
void main()
{
int c, *b, **a;
c = 4;
b = &c;
a = &b;
printf( "%d", f(c,b,a));
getchar();
}
A) 18
B) 19
C) 21
D) 22
ANSWER: B
What does the following fragment of C program print?
char c[] = "GATE2011";
char *p = c;
printf("%s", p + p[3] - p[1]);
A) GATE2011
B) E2011
C) 2011
D) 011
ANSWER: C
The smallest element of an array's index is called its
A) Lower bound.
B) Upper bound.
C) Range.
D) Extraction.
ANSWER: A
O(N)(linear time) is better than O(1) constant time.
A) True
B) False
ANSWER: B
For 'C' programming language
A) Constant expressions are evaluated at compile
B) String constants can be concatenated at compile time
C) Size of array should be known at compile time
D) All of these
ANSWER: D
What is the maximun number of dimensions an array in C may have?
A) Two
B) Eight
C) Twenty
D) Theoratically no limit. The only practical limits are memory size and co
mpilers
ANSWER: D
If x is an array of interger, then the value of &x[i] is same as
A) &x[i-1]+sizeof(int)
B) x+sizeof(int)*i
C) x+i
D) none of these
ANSWER: C
If S is an array of 80 characters, then the value assigned to S through
the statement scanf("%s",S) with input 1 2 3 4 5 would be
A) "12345"
B) nothing since 12345 is an integer
C) S is an illegal name for string
D) %s cannot be used for reading in values of S
ANSWER: A
Size of the array need not be specified, when
A) Initialization is a part of definition
B) It is a declaratrion
C) It is a formal parameter
D) All of these
ANSWER: D
A one dimensional array A has indices 1....75.Each element is a string a
nd takes up three memory words. The array is stored starting at location 1120
decimal. The starting address of A[49] is
A) 1167
B) 1164
C) 1264
D) 1169
ANSWER: C
Minimum number of interchange needed to convert the array 89,19,40,14,17
,12,10,2,5,7,11,6,9,70, into a heap with the maximum element at the root is
A) 0
B) 1
C) 2
D) 3
ANSWER: C
Which of the following is an illegal array definition?
A) Type COLOGNE:(LIME,PINE,MUSK,MENTHOL); var a:array[COLOGNE]of REAL;
B) var a:array[REAL]of REAL;
C) var a:array['A'..'Z']of REAL;
D) var a:array[BOOLEAN]of REAL;
ANSWER: B
#include<stdio.h>
#include<stdarg.h>
void fun1(int num, ...);
void fun2(int num, ...);
int main()
{
fun1(1, "Apple", "Boys", "Cats", "Dogs");
fun2(2, 12, 13, 14);
return 0;
}
void fun1(int num, ...)
{
char *str;
va_list ptr;
va_start(ptr, num);
str = va_arg(ptr, char *);
printf("%s ", str);
}
void fun2(int num, ...)
{
va_list ptr;
va_start(ptr, num);
num = va_arg(ptr, int);
printf("%d", num);
}
A) Dogs 12
B) Cats 14
C) Boys 13
D) Apple 12
ANSWER: A
#include<stdio.h>
#include<stdarg.h>
fun(...);
int main()
{
fun(3, 7, -11.2, 0.66);
return 0;
}
fun(...)
{
va_list ptr;
int num;
va_start(ptr, n);
num = va_arg(ptr, int);
printf("%d", num);
}
A) Error: fun() needs return type
B) Error: ptr Lvalue required
C) Error: Invalid declaration of fun(...)
D) No error
ANSWER: C
#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);
int main()
{
display(4, 'A', 'a', 'b', 'c');
return 0;
}
void display(int num, ...)
{
char c; int j;
va_list ptr;
va_start(ptr, num);
for(j=1; j<=num; j++)
{
c = va_arg(ptr, char);
printf("%c", c);
}
}
A) Error: unknown variable ptr
B) Error: Lvalue required for parameter
C) No error and print A a b c
D) No error and print 4 A a b c
ANSWER: C
The value of a resistor creating thermal noise is doubled the noise powe
r generated is therefore
A) Halved
B) Quadrupled
C) Unchanged
D) Doubled
ANSWER: C
De-emphasis circuit is used
A) After modulation
B) Prior to modulation
C) To de-emphasis low frequency component
D) To de-emphasis high frequency component
ANSWER: D
The capacity of a channel is
A) Number of digits used in coding
B) Volume of information it can take
C) Maximum rate of information transmission
D) Bandwidth required for information
ANSWER: C
void main()
{
int const *p=5;
printf("%d"' ++(*p));
}
A) 6
B) 5
c) Garbage value
D) compilier Error
ANSWER: D
main()
{
static int var=5;
printf("%d"'var--);
if(var)
main();
A) 1.55555
B) 54321
C) infinite loop
D) None
ANSWER: B
main()
{
char *p;
printf("%d%d",size of(*p),size of(p));
A) 11
B) 12
C) 21
D) 22
ANSWER: B
main()
{
int c=--2;
printf("c=%d",c);
}
A) 1
B) -2
C) 2
D) Error
ANSWER: B
#define int char
main()
{
inti=65;
printf("size of(i)=%d",size of(i));
}
A) size of(i)=2
B) size(i)=1
C) compiler error
D) None
ANSWER: B
main()
{
char string[]="Helloworld"
display(strings);
}
void diaplay(char*string)
{
printf("%s",string)
}
A) compiler Error
B) Helloworld
C) can't say
D) None
ANSWER: A
#define square(*)***
main()
{
int i;
i=64/squqre(4);
printf("%d",i);
}
A) 4
B) 64
C) 16
D) None
ANSWER: B
The parameters in a function definition are _________.
A) actual parameters.
B) formal parameters.
C) dummy parameters.
D) optional.
Answer: B
Recursive call results when ________.
A) a function calls itself.
B) a function1 calls another function, which in turn calls the function1.
C) both 1 & 2.
D) a function calls another function.
Answer: C
The storage class allowed for parameters is _________.
A) auto storage class.
B) static storage class.
C) extern storage class.
D) register storage class.
Answer: C
Functions have ________.112-C Programming
A) file scope.
B) local scope.
C) block scope.
D) function scope.
Answer: A
The function floor(x) in math.h __________.
A) returns the value rounded down to the next lower integer.
B) returns the value rounded up to the next higher integer.
C) the next lower value.
D) the next higher value.
Answer: A
The function strcpy(s1,s2) in string.h __________.
A) copies s1 to s2.
B) copies s2 to s1.
C) appends s1 to end of s2.
D) appends s2 to end of s1.
Answer: B
The function strcat(s1,s2) in string.h __________.
A) copies s1 to s2.
B) copies s2 to s1.
C) appends s1 to end of s2.
D) appends s2 to end of s1.
Answer: D
The function strcmp(s1,s2) returns zero _________.
A) if s1 is lexicographically less than s2.
B) if s1 is lexicographically greater than s2.
C) if both s1 ans s2 are equal.
D) if s1 is empty string.
Answer: C
What will be the output of following program ?
#include<stdio.h>
int main( )
{
float a=5,b=2;
int c,d;
c =a%d;
d =a/2;
printf("%d\n",d);
return 0;
}
A) 3
B) 2
C) Error
D) None of above
ANSWER: C
What is error in following declaration?
struct outer{
int a;
struct inner{
char c;
};
};
A) Nesting of structure is not allowed in c.
B) It is necessary to initialize the member variable.
C) Inner structure must have name.
D) Outer structure must have name.
ANSWER: C
What will be the output of program ?
#include<stdio.h>
int main( )
{
printf("nn /n/n nn/n");
return 0;
}
A) Nothing
B) nn /n/n nn
C) nn /n/n
D) Error
ANSWER: B
What will be the output of program ?
#include<stdio.h>
int main( )
{
int a,b;
printf("Enter two values of a and b");
scanf("%d%d",&a,&b);
printf("a=%d b=%d"a,b);
return 0;
}
A) a = 0 b = 0
B) a = 1 b = 1
C) Values you entered
D) None of above
ANSWER: C
A character variable can at a time store ?
A) 1 character
B) 8 character
C) 254 character
D) None of above
ANSWER: A
The maximum value that an integer constant can have is ?
A) -32767
B) 32767
C) 1.7014e + 38
D) -1.7014e + 38
ANSWER: B
What will be output if you will compile and execute the following c code
?
void main(){
int array[]={10,20,30,40};
printf("%d",-2[array]);
}
(A) -60
(B) -30
(C) 60
(D) Garbage value
ANSWER: B
Which of the following is false in C ?
A) Keywords cannot be used as variable names
B) Variable names can contain a digit
C) Variable names do not contain a blank space
D) Capital letters can be used in variable names
ANSWER: A
On which if the following operator can % operator NOT be used ?
A) int variable
B) float variable
C) int constant
D) All of above
What is the output of the following code?
#include
void main()
{
int s=0;
while(s++<10)
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
A) 10..10
B) 10..50
C) ERROR
D) 0
ANSWER: C
void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?
A) XAM is printed
B) exam is printed
C) Compiler Error
D) Nothing is printed
ANSWER: C
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
A) 11
B) 7
C) 5
D) 9
ANSWER: A
The function toupper(ch) in ctype.h _________.
A) returns the upper case alphabet of ch.
B) returns the lower case alphabet of ch.
C) returns the upper case if ch is lower case, and lower case if ch is uppe
r case.
D) is a user-defined function.
Answer: A
The function tolower(ch) in ctype.h _________.
A) returns the upper case alphabet of ch.
B) returns the lower case alphabet of ch.
C) returns the upper case if ch is lower case, and lower case if ch is uppe
r case.
D) is a user-defined function.
Answer: B
Which of the following would compute the square of x in C?
A) pow(2,x);
B) pow(x,2);
C) x**2;
D) powe(x,2);112-C Programming
Answer: B
All standard C library <math.h> functions return what data type?
A) decimal.
B) float.
C) double.
D) int.
Answer: C
When a function is recursively called all automatic variables are ______
___.
A) stored in stack.
B) stored in queue.
C) stored in array.
D) stored in linked list.
Answer: A
What is the output of the following code?
main()
{
printf(%d\n,sum(5));
}
int sum(int n)
{
if(n<1) return n;
else return(n+sum(n-1));
}
A) 10.
B) 16.
C) 14.
D) 15.
Answer: D
Pointers are supported in __________.
A) FORTRAN.
B) PASCAL.
C) C.
D) both options 2 and 3 .
Answer: D
Pointer variable may be assigned ______.
A) an address value represented in hexadecimal.
B) an address value represented in octal.
C) the address of another variable .
D) an address value represented in binary.
Answer: C
The operators exclusively used in connection with pointers are________.
A) * and /.
B) & and *.
C) & and |.
D) and >.
Answer: B112-C Programming
Identify the wrong declaration statement.
A) int *p, a=10.
B) int a=10,*p=&a.
C) int *p=&a, =10 .
D) options 1 and 2.
Answer: C
Identify the invalid expression , int num=15, *p=&num.
A) *num.
B) *(&num).
C) *&*&num.
D) **&p.
Answer: A
How does the compiler differentiate address of operator from bitwise AND
operator?
A) by using the number of operands and position of operands.
B) by seeing the declaration.
C) both options 1 and 2.
D) by using the value of the operand.
Answer: A
The address of operator returns _________.
A) the address of its operand.
B) 1 value.
C) both options 1 and 2.
D) r value.
Answer: A
Pointer variable may be initialized using _________.
A) static memory allocation.
B) dynamic memory allocation.
C) both options (a) and (b).
D) a positive integer.
Answer: C
The number of arguments used in malloc ( ) is _________.
A) 0.
B) 1.
C) 2.
D) 3.
Answer: B
The function used for dynamic deallocation of memory is __________.
A) destroy ( ).
B) delete ( ).
C) free ( ).
D) remove ( ).
Answer: C
The pointers can be used to achieve _________/
A) call by function.
B) call by reference.
C) call by name.112-C Programming
D) call by procedure.
Answer: B
Identify the correct statement for given expression
Float fnum [10], *fptr = fnum.
A) fnum is pointer variable.
B) fnum is a fixed address and not a variable.
C) fnum is an array variable.
D) fnum is an address that can be modified.
Answer: B
Given int a[5];how to declare array in the function definition if the fu
nction call is
sort(a)?
A) sort(int *a).
B) sort(int a[5]).
C) both options (a) and (b).
D) sort(int a).
Answer: C
Given int *p1,**p2,***p3,v=25;
How to obtain the value of v using pointer variable?
A) *p1.
B) **p2.
C) ***p3.
D) all the above.
Answer: D
The declaration float *a[5];is ________.
A) an ordinary array.
B) a pointer to an array.
C) an array of pointers.
D) pointer to an array.
Answer: C
Given char *p=ANSI C; identify the expression returning the value C.
A) strcpy(t[0],BASIC);
B) t[0]=JAVA;
C) both options 1 and 2.
D) both options 2 and 3.
Answer: B
Given char *p=ANSI C; identify the expression returning the value C.
(A) strcpy(t[0],BASIC);
(B) t[0]=JAVA;
(C) both options 1 and 2.
(D) both options 2 and 3.
Answer: B
The arguments argc in main( ) counts __________.
A) the number of command line strings including the execution command.
B) the number of command line strings excluding the execution command.
C) the number of lines in a program.
D) the number of characters in a program.
Answer: A
In the declaration double (*pf)( ); __________.
A) pf is a pointer to a function.
B) pf is a function returning pointer.
C) pf is a pointer to array.
D) pf is an array of pointers.112-C Programming
Answer: A
The operation that can be performed on pointers are __________.
A) addition and subtraction of a pointer and an integer.
B) assignment of pointer using pointer expression.
C) assignment of the value 0 to a pointer.
D) all the above.
Answer: D
When applied to a variable, what does the unary & operator yield?
A) the variables value.
B) the variables address.
C) the variables format.
D) the variables right value.
Answer: B
Which of the following is the most accurate statement about runtime mem
ory?
A) memory is allocated by using malloc ( ).
B) memory is freed by a garbage collector.
C) allocated memory can be freed by calling free ( ).
D) Both options 1 and 3.
Answer: D

char *ptr;
char string [ ]=project;
ptr +=(ptr+5);
What string does ptr contain in the sample code above?
A) ct.
B) ject.
C) object.
D) Unknown. This code is incorrect.
Answer: D
Scrutinize the following code in C.
Char fruit [ ]=Orange;
Char *ptr;
ptr =fruit;
What will be the output for the following expression?
A) r.
B) a.
C) n.
D) none.
Answer: B

main ( )
{
int a=5,*ptr;
ptr=&a;
printf (%d,++*ptr);
}
The output might be _________.
A) 6.112-C Programming
B) 5.
C) 0.
D) none.
Answer: A
main ( )
{
Char x [25], y [25],*p=y;
Strcpy (x, BIRTHDAY);
Strcpy (y, HAPPY);
P=x;
Strcpy (x, MOTHER);
*p= D;
printf (p=%s\n, p);
}
What will be the output when the sample code is executed?
A) p=DOTHERDAY.
B) p=MOTHERDAY.
C) p=DOTHER.
D) p=DIRTHDAY.
Answer: C
Which statement correctly defines a character string with a length of 4
plus 1 for the
terminating NUL?
A) char string[ ];.
B) char* string[ ];.
C) char * string[5];.
D) char string[5];.
Answer: D
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) 7.
B) 8.
C) 9.
D) The code will not compile.
Answer: C

What memory function should be used to allocate memory in which all bit
s are
initialized to 0?
A) calloc.
B) malloc.
C) alloc.
D) memalloc.
Answer: A
int *const size = 10;
If the address of size is 3024, then size ++ is ________.
A) 11.112-C Programming
B) 3025.
C) 3026.
D) invalid.
Answer: D
The amount of memory to be allocated for the following array of pointers
short *p[4]; is _________.
A) no memory.
B) 4 bytes.
C) 6 bytes.
D) 16 bytes.
Answer: D
int x = 1;
int *ptr=malloc(sizeof(int));
ptr=&x;
x+2;
*ptr+3;
Is there anything wrong with the above code?
A) No ,x will be set to 2.
B) No, x will be set to 3.
C) Yes, There will be a memory overwrite.
D) Yes, There will be a memory leak.
Answer: C
main ( )
{
int a[4][2];
int b=0,x;
int i,y;
for (i=0; i<4; i++)
for(y=0;y<2;y++)
a[i][y] = b++
x=*(*(a+2)-1);
}
What is the value of x in the above samples?
A) 2.
B) 3.
C) 4.
D) 5.
Answer: B
float (*f[5] ( ) ); This declaration represents _________.
A) pointer to function returning array of float.
B) pointer to array of pointer to function returning float.
C) array of pointers to function returning array of float.
D) array of pointers to function returning float.
Answer: D
float (*(*f[5]) ( ) )[10]; This declaration represents _________.
A) array[5] of function returning a pointer to array[10] of float.112-C Pro
gramming
B) array of pointer returning pointer to array[10] of float.
C) array[5] of pointer to a function returning a pointer to array[10] of fl
oat.
d) none.
Answer: C
int a=1; b=2; c=3; *pointer;
pointer=&c;
a=c/*pointer;
b=c;
printf(a=%d b=%d,a,b);
What will be the output?
A) a=1 b=3.
B) a=3 b=3.
C) 2.
D) Error.
Answer: D
Which are valid?
A) Pointers can be added.
B) pointers can be subtracted.
C) integers can be added to pointers.
D) Both 1 and 2. all correct.\
Answer: A
p and q are pointers to the same type of data items.
Which of these are valid?
A) *(p+q).
B) *(p-q).
C) *p-*q.
D) none of the above.
Answer: C
int *i
float *f;
char *c;
Which are valid castings?
A) (int*)&c.
B) (float*)&c.
C) (char*)&i.
D) all of the above.
Answer: A
What is the result of the expression or the following declaration?
int A [ ]={1,2,3,4,5};
*A+1-*A+3
A) 2.
B) -2.
C) 4.
D) none of the above.
Answer: C
Structure is a __________.112-C Programming
A) scalar data type.
B) derived data type.
C) both options 1 and 2.
D) primitive data type.
Answer: B
Structure is a data type in which ________.
A) each element must have the same data type.
B) each element must have pointer type only.
C) each element may have different data type.
D) no element is defined.
Answer: C
C provides a facility for user defined data type using ________.
A) pointer.
B) function.
C) structure.
D) array.
Answer: B
Structure declaration __________.
A) describes the prototype.
B) creates structure variable.
C) defines the structure function.
D) is not necessary.
Answer: A
A structure ________.
A) can be read as a single entity.
B) cannot be read s a single entity.
C) can be displayed as a single entity.
D) has a member variable that cannot be individually read.
Answer: B
A structure can have ___________.
a) pointers as its members.
b) scalar data type as its members.
c) structure as its member.
d) all the above.
Answer: C
In a structure definition, __________.
A) initialization of structure members are possible.
B) initialization of array of structures are possible.
C) both options 1 and 2.
D) initialization of array of structures are not possible.
Answer: C
The operator exclusively used with pointer to structure is _______.
A) ..
B) ? .
C) [ ].
D) *112-C Programming
Answer: B
If one or more members of a structure is created ,then the structure is
known as
____________.
A) nested structure.
B) invalid structure.
C) self-referential structure.
D) unstructured structure.
Answer: A
The changes made in the members of a structure are not available in the
calling function
if __________.
A) pointer to structure is passed as argument.
B) the members other then pointer type are passed as arguments.
C) structure variable passed as argument.
D) both options 1 and 2.
Answer: A
#include<stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
A) 50
B) 10
C) compile Error
D) None
ANSWER: A
#define clrscr() 100
main()
{
clrscr();
printf("%d/n");
clrscr();
A) 0
B) 1
C) 100
D) None
ANSWER: C
main()
{
int i=1;j=2;
switch(i)
{
case i:printf("GOOD");break;
case j;printf("BAD");break;
}
}
a) Good
b) Bad
c) GOOD Bad
D) Error
ANSWER: D
main()
{
int i=0;
for(;i++;prntf("%d",i));
printf("%d",i);
}
A) 1
B) 11
C) 12
D) Error
ANSWER: A
main()
{
extern int i;
i=20;
printf("%d",size of(i));
}
A) 20
B) 2
C) compile Error
D) Linear Error
ANSWER: D
main()
{
int i=0;j=0;
if(i&&j++)
printf("%d..%d",i++,j);
printf("%d..%d",i,j);
}
A) 0..1
B) 1..0
C) 0..0
D) 1..1
ANSWER: D
void main()
{
static int i=5;
if(--i)
{
main();
printf("%d",i);
}
}
A) 54321
B) 0000
C) infiniteloop
D) None
ANSWER: B
#include
main()
{
register i=5;
char j[]=("hello");
printf("%s%d",j,i);
}
A) Hello 5
B) Hello garbage value
C) Error
D) None
ANSWER: A
main()
{
int i=abc(10);
printf("%d\n",--i);
}
int abc(int i)
{
return(i++);
}
A) 10
B) 9
C) 11
D) None
ANSWER: B
void main()
{
static int i=i++,j=j++,k=k++;
printf("%d%d%d",i,j,k);
}
A) 111
B) 000
C) Garbage value
D) Error
ANSWER: A
#define pnod(a,b) a*b
main()
{
int x=3,y=4;
printf("%d,pnod(x+2,y-1));
}
A) 15
B) 10
C) 12
D) 11
ANSWER: B
main()
{
char p[]="%d\n";
p[1]='c';
printf(p,65);
A) 65
B) C
c) A
D) Error
ANSWER: C
What is the return value of f( p,p) if the value of p is initialized to
5 before the call? Note that the first parameter is passed by reference, where
as the second parameter is passed by value.
int f( int & x, int c)
{
c= c- 1;
If( c== 0) return 1;
X= x+ 1; return f (x,c) * x;
}
A) 3024
B) 6561
C) 55440
D) 161051
ANSWER: c
What will be the output of the following program ?
#include
void main()
{
int a = 2;
switch(a)
{
case 1:
printf("goodbye");
break;
case 2:continue;
case 3:printf("bye");
}
}
A) error
B) goodbye
C) bye
D) byegoodbye
ANSWER: A
3. 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
ANSWER: A
Identify the wrong statement.
A) Structure variable can be passed as argument.
B) Pointer to structure can be passed as argument.
C) Member variable of a structure can be passed as argument.
D) none of the above.
Answer: D
Structure is used to implement the ________ data structure .
A) stack.
B) queue.
C) tree.
d) all the above .
Answer: D
A bit field is __________.
A) A pointer variable in a structure.
B) One bit or set of adjacent bits within a word.
C) A pointer variable in a union.
D) Not used in C.
Answer: B
struct car
{
int speed;
Char type [10];
} vehicle;
struct car *ptr;
ptr=&vehicle;
Referring to the sample code above,which of the following will make the
speed equal to
200?
A) (*ptr).speed=200;.
B) (*ptr)?speed=200;.
C) *ptr.speed=200;.
D) &ptr.speed.112-C Programming
Answer: A
File is ___________.
A) a data type.
B) a region of storage .
C) both option 1 and 2.
D) a variable.
Answer: B
The way to access file are accessed through______.
A) by using library functions.
B) by using system calls.
C) both options 1 and 2 .
D) to use a linker.
Answer: C
Low level files are accessed through ________.
A) system calls.
B) library functions.
C) linker.
D) loader.
Answer: A
C supports _________.
A high level files.
B low level files.
C both options 1 and 2.
C executable files only.
Answer: C
I/O stream can be _________.
A a text steam.
B a binary stream.
C both options 1 and 2.
D an I/O operation.
Answer: C
File opening is ___________.
A a default action in file processing.
B an action of connecting a program to a file.
C not necessary.
D not using any library function.
Answer: B
FILE defined in stdio.h is ____________.
A a region of storage.
B a data type.
C not a data type.
D a variable.
Answer: B
A file pointer is ___________.
A a stream pointer.
B a buffer pointer.112-C Programming
C a pointer to FILE data type.
D all the above.
Answer: D
If fopen ( ) fails, it returns __________.
A -1.
B NULL.
C 1.
D the file pointer.
Answer: B
The action of connecting a program to a file is obtained by using ______
____.
A fclose ( ).
B delete( ).
C fdisconnect( ).
D clear ( ).
Answer: A
The value returned by fclose( ), if an error occurs is _______.
A 0.
B 1.
C EOF.
D -1.
Answer: C
The function(s) used for reading a character from a file is (are) _____
_____.
a. getc( ).
b. getc.
c. both options 1 and 2.
d. getchar( ).
Answer: C
The function used for random access of a file is __________.
A fseek( ).
B ftell( ).
C search( ).
D rewind( ).
Answer: A
What is the value of origin used in fseek(fptr,position,origin);? To re
present end of file.
A 0.
B 1.
C 2.
D START.
Answer: A
If an error occurs, the function fseek( ) returns __________.
A non-zero.
B zero.
C OK.
D READY.
Answer: B112-C Programming
The value returned by ftell( ) if an error occurs is ___________.
A -1.
B 0.
C Positive value.
D MIN_INT.
Answer: A
The function used for writing to binary streams is _____________.
A write ( ).
B fwrite( ).
C fprintf( ).
D all the above.
Answer: B
Identify the functions for in-memory format conversions ___________.
A realloc( ).
B sprintf( ).
C sscanf( ).
D both options 2 and 3.
Answer: D
The value of string after executing the following statements is
int x=25; char string[5];
sprintf(string. %d, x);
A 25.
B 25.
C TWO FIVE.
D 25000.
Answer: A
Identify the correct statement.
A # include filename.
B # include <filename>.
C both options 1 and 2.
D # include filename.
Answer: C
The following line a program # represents ______.
A an invalid code.
B a null code.
C a comment.
D a page number.
Answer: B
Macros _________.
A can be recursively defined.
B cannot be recursively defined.
C cannot be defined.
D are not preprocessor facility.
Answer: B
Identify the token passing operator.
A +.112-C Programming
B ++.
C #.
D ##.
Answer: D
The directive(s) used in conditional compilation is (are) __.
A #if.
B #elif.
C #else.
D all the above.
Answer: D
Functions may use_______.
A varying number of parameters.
B fixed number of parameters.
C no argument.
D at most five arguments.
Answer: A
Identify the trigraph sequence for #
A ??/.
B ??=.
C ??.
D ??!.
Answer: B
Which of the following is valid for opening a read-only ASCII file?
A fileOpen (filenm, read);.
B fopen (filenm, r);.
C fileOpen (filenm, r);.
D fopen (filenm, read);.
Answer: B
What are two predefined FILE pointers in C?
A stdout and stderr.
B console and error.
C stdout and stdio.
D stdio and stderr.
Answer: A
Which of the following is NOT a valid preprocessor directive?
A #if.
B #line.
C #elseif.
D #pragma.
Answer: C
The function used to position the file pointer in C is __________.
A seekg( ).
B fseekg( ).
C fseek( ).
D fileseek( ).
Answer: C112-C Programming
Which of the following function returns calendar time to local time?
A Gmtime.
B ctime.
C strtime.
D asctime.
Answer: B
Which ANSI C standard function could be used to sort a string array?
A Qsort.
B sort.
C assort.
D bsort.
Answer: A
Which is the fundamental data type is used to implement the enum data ty
pe?
A Char.
B int.
C float.
D double.
Answer: B
#define max(a,b) (a>b?b:a)
#define squre(x) x*x
int i=2,j=3,k=1;
printf(%d %d, max(i,j), squre(k) );
What is the output generated by the above code?
A 3 2.
B 3 1.
C 2 1.
D 2 2.
Answer: C
What is the value of CAR in the following enumeration?
enum transport
{
SCOOTER=1, BUS=4, CAR, TRAIN=8
};
A 0.
B 5.
C 7.
D 4.
Answer: B
What is the value of LOTUS in the following enumeration?
enum symbol
{
HAND, SUN, LOTUS, UMBRELLA
};
A 0.
B 3.112-C Programming
C 2.
D None of the above.
Answer: C
What is the output of the following code?
enum fruits
{
APPLE=1, ORANGE=1, GRAPES=3, PINEAPPLE
};
printf (%d,ORANGE);
A Compilation error.
B Execution error.
C 2.
D 1.
Answer: D
What will be the output for the following code?
enum control
{
On, off, neutral
};
PRINTF (%d, off);
A Compilation error.
B Execution error.
C 5.
D 1.
Answer: A
If there is a need to see output as soon as possible, which of the foll
owing will force the
output from the buffer into the output stream?
A write ( ).
B output ( ).
C flush ( ).
D fflush ( ).
Answer: D
What will be the value of j in the following code?
A 24.
B 25.
C 28.
D 32.
Answer: B
The qualifier const __________.
A defines a constant name.
B keeps the value of a variable constant during execution of a program.
C both options 1 and 2.
D does not keep value of variable constant.
Answer: B
The keyword used to represent a structure data type is______.
A sructure.112-C Programming
B struct.
C struc.
D structr.
Answer: B
After the execution of the statement int x; the value of x is
A 0.
B undefined.
C 1.
D -1.
Answer: B
After the execution of the statement int x; the value of x is
A) 0.
B) undefined.
C) 1.
D) -1.
Answer: B
int z, x=5, y=-10, a=4, b=2;
z=x++ - --y * b / a;
What number will z in the sample code above contain?
A) 5
B) 6
C) 10
D) 11
Answer: C
With every use of a memory allocation function, what function should be
used to release
allocated memory which is no longer needed?
A) unalloc()
B) dealloc()
C) release()
D) free()
Answer: D
void *ptr;
myStruct myArray[10];
ptr = myArray;
Which of the following is the correct way to increment the variable "ptr
"?
A) ptr = ptr + sizeof(myStruct);
B) ++(int*)ptr;
C) ptr = ptr + sizeof(myArray);
D) increment(ptr);
Answer: A
"My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above
.
A) printf("\"My salary was increased by 15/%\!\"\n");
B) printf("My salary was increased by 15%!\n");
C) printf("My salary was increased by 15'%'!\n");
D) printf("\"My salary was increased by 15%%!\"\n");
Answer: D
What is a difference between a declaration and a definition of a variabl
e?
A) Both can occur multiple times, but a declaration must occur first.
B) There is no difference between them.
C) A definition occurs once, but a declaration may occur many times.
D) A declaration occurs once, but a definition may occur many times.112-C P
rogramming
Answer: D
206. int a=10, b;
b = a++ + ++a;
printf(%d,%d,%d,%d,b,a++,a,++a);
what will be the output when following code is executed
A) 12,10,11,13.
B) 22,10,11,13.
C) 22,11,11,11.
D) 22,13,13,13.
Answer: D
#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.
Answer: D
int x = 2 * 3 + 4 * 5;
What value will x contain in the sample code above?
A) 22.
B) 26.
C) 46.
D) 50.
Answer: B
int var1;
If a variable has been declared with file scope, as above, can it safely
be accessed
globally from another file?
A) Yes; it can be referenced through the register specifier.
B) No; it would have to have been initially declared as a static variable.
C) No; it would need to have been initially declared using the global keywo
rd
D) Yes; it can be referenced through the publish specifier.
Answer: C
C is a ___________ language.
A) Machine.
B) Procedural.
C) Assembly .
D) Object-oriented.
Answer: B
In a C expression, how is a logical AND represented?
A) @@ .
B) || .
B) AND.
B) && .
Answer: D
How do printf()'s format specifiers %e and %f differ in their treatment
of floating-point112-C Programming
numbers?
A) %e always displays an argument of type double in engineering notation; %
f always
displays an argument of type double in decimal notation.
B) %e expects a corresponding argument of type double; %f expects a corresp
onding
argument of type float.
C) %e displays a double in engineering notation if the number is very small
or very large.
Otherwise, it behaves like %f and displays the number in decimal notatio
n.
D) %e displays an argument of type double with trailing zeros; %f never dis
plays trailing
zeros.
Answer: A
Which one of the following will read a character from the keyboard and w
ill store it in
the variable c?
A) c = getc();
B) getc( &c );
C) c = getchar( stdin );
D) c = getchar();
Answer: D
#include<stdio.h>
int i;
void increment(int i)
{
i++;
}
int main()
{
for(i=0;i<10;increment(i))
}
printf(i=%d\n,i);
return 0;
}
What will happen when the program above is compiled and executed?
A) It will not compile.
B) It will print out: i=9.
C) It will print out: i=10.
D) It will loop indefinitely.
Answer: D
Which one of the following C operators is right associative?
A) = .
B) , .
c) [] .
D) ^ .
Answer: A
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.11
2-C Programming
C) It automatically increments the variable when used.
D) It automatically initializes a variable to NULL.
Answer: A
How do you include a system header file called sysheader.h in a C source
file?
A) include <sysheader.h> .
B) #incl "sysheader.h" .
C) #includefile <sysheader>.
D) #include sysheader.h .
Answer: B
According to the Standard C specification, what are the respective minim
um sizes (in
bytes) of the following three data types: short; int; and long?
A) 1, 2, 2 .
B) 1, 2, 4.
C) 1, 2, 8.
D) 2, 2, 4.
Answer: A
penny = one
nickel = five
dime = ten
quarter = twenty-five
How is enum used to define the values of the American coins listed above
?
A) enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};
B) enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});
C) enum coin {penny=1,nickel=5,dime=10,quarter=25};
D) enum coin (penny=1,nickel=5,dime=10,quarter=25);
Answer: D
char txt [20] = "Hello world!\0";
How many bytes are allocated by the definition above?
A) 11 bytes.
B) 12 bytes.
C) 13 bytes.
D) 20 bytes.
Answer: C
int i = 4;
int x = 6;
double z;
z = x / i;
printf(z=% .2f\n, z);
What will print when the sample code above is executed?
A) z=0.00.
B) z=1.00.
C) z=1.50.
D) z=2.00 .
Answer: D
Which one of the following variable names is NOT valid?112-C Programming
A) go_cart.
B) Go4it .
C) 4season.
D) 4.
Answer: B
How is a variable accessed from another file?
A) The global variable is referenced via the extern specifier.
B) The global variable is referenced via the auto specifier.
C) The global variable is referenced via the global specifier.
D) The global variable is referenced via the pointer specifier.
Answer: C
When applied to a variable, what does the unary "&" operator yield?
A) The variable's value.
B) The variable's binary form.
C) The variable's address.
D) The variable's format.
Answer: A
long factorial (long x)
{
return x * factorial(x - 1);
}
With what do you replace the ???? to make the function shown above retur
n the correct answer?
A) if (x == 0) return ;
B) return 1;
C) if (x >= 2) return 2;
D) if (x <= 1) return 1;
ANSWER: D
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
ANSWER: A
#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 -- 11 -- 1
B) 1 -- 12 -- 1
C) 1 -- 12 -- 2
D) 1 -- 11 2
ANSWER: D
What will be the value of `a` after the following code is executed
#define square(x)
x*xa = square(2+3)
A) 25
B) 13
C) 11
D) 0
ANSWER: C
#include
void main()
{
int a = 36, b = 9;
printf("%d",a>>a/b-2);
}
A) 9
B) 7
C) 5
D) none of these
ANSWER: A
What will be the output of the following statements ?
int a = 4, b = 7,c; c = a = = b;
printf("%i",c);
A) 0
B) error
C) 1
D) garbage value
ANSWER: A
What will be the output of the following statements ?
int a = 5, b = 2, c = 10,
i = a>b
void main()
{
printf("hello");
main();
}
A) 1
B) 2
C) infinite number of times
D) none of these
ANSWER: c
What will be the output of the following statements ?
int x[4] = {1,2,3};
printf("%d %d %D",x[3],x[2],x[1]);
A) 03%D
B) 000
C) 032
D) 321
ANSWER: c What will be the output of following code ?
#include<stdio.h>
void main( )
{
char suite =3;
switch(suite)
{
case 1:
printf("ALL QUIZ");
case 2:
printf("All quiz is great");
default:
printf("All quiz contains MCQs");
}
printf("Are you like All quiz ?");
}

A) ALL QUIZ
B) All quiz is great
C) All quiz contains MCQs
D) All quiz is great Are you like Al quiz ?
ANSWER: D
What will be the output of following code ?
void main( )
{
int c=3;
switch(c)
{
case '3':
printf("Hi");
break;
case 3:
printf("Hello");
break;
default:
printf("How r u ?");
}
}


A) Hi
B) Hello
C) How r u ?
D) None of above
ANSWER: B
What will be the output of following program ?
void main( )
{
int 1=3;
switch(i)
{
case 0:
printf("I am here");
case 1+0:
printf("I m in second case");
case 4/2:
printf("I m in third case");
case 8%5:
printf("Good bye");
}
}
A) All case statements will be executed
B) I am here
C) Good bye
D) I am in third case
ANSWER: C
What will be the output of following ?
void main( )
{
int suite =1;
switch(suite);
{
case 0:
printf("Its morning time");
case 1:
printf("Its evening time");
}
}
A) Error
B) Its morning time
C) Its evening time
D) None of above
ANSWER: A
What will be the output of following program ?
#include<stdio.h>
int main( )
{
int i=2,j=3,k,l;
float a,b;
k = i/j * j;
l = j/i * j;
a = i/j * j;
b = j/i * i;
printf("%d %d%f%f\n",k,l,a,b);
return 0;
}
A) 3, 0, 0, 0
B) 0, 3, 0.000000, 2.000000
C) 0,0,0,0
D) Error
ANSWER: B
What will be the output of following program ?
#incllude<stdio.h>
int main( )
{
int a,b;
a = -3 - - 25;
b = -3 - - (-3);
printf("a=%d b=%d\n",a,b);
return 0;
}
A) a = 22 b = -6
B) a = -6 b = 22
C) a = 3 b = 3
D) No Output
ANSWER: A
What will be the output of following program ?
#include<stdio.h>
int main( )
{
float a=5,b=2;
int c,d;
c =a%d;
d =a/2;
printf("%d\n",d);
return 0;
}
A) 3
B) 2
C) Error
D) None of above
ANSWER: C
What will be the output of program ?
#include<stdio.h>
int main( )
{
printf("nn /n/n nn/n");
return 0;
}
A) Nothing
B) nn /n/n nn
C) nn /n/n
D) Error
ANSWER: B
What will be the output of program ?
#include<stdio.h>
int main( )
{
int a,b;
printf("Enter two values of a and b");
scanf("%d%d",&a,&b);
printf("a=%d b=%d"a,b);
return 0;
}
A) a = 0 b = 0
B) a = 1 b = 1
C) Values you entered
D) None of above
ANSWER: C
A character variable can at a time store ?
A) 1 character
B) 8 character
C) 254 character
D) None of above
ANSWER: A
The maximum value that an integer constant can have is ?
A) -32767
B) 32767
C) 1.7014e + 38
D) -1.7014e + 38
ANSWER: B
Which of the following is false in C ?
A) Keywords cannot be used as variable names
B) Variable names can contain a digit
C) Variable names do not contain a blank space
D) Capital letters can be used in variable names
ANSWER: A
On which if the following operator can % operator NOT be used ?
A) int variable
B) float variable
C) int constant
D) All of above
What is the output of the following code?
#include
void main()
{
int s=0;
while(s++<10)
# define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
A) 10..10
B) 10..50
C) ERROR
D) 0
ANSWER: C
void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?
A) XAM is printed
B) exam is printed
C) Compiler Error
D) Nothing is printed
ANSWER: C
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
A) 11
B) 7
C) 5
D) 9
ANSWER: A
Which one of the following is NOT a valid identifier?
A) __ident.
B) auto.
C) bigNumber.
D) g42277.
Answer: C
A character variable can at a time store__________.
A) 1 character.
B) 8 characters.
C) 254 characters.
D) 22 characters.
Answer: B
An integer constant in C must have ___________.
A) At least one digit.
B) At least one decimal point.
C) A comma along with digits.
D) Digits separated by commas.
Answer: A
The break statement is used to exit from_________.
A) An if statement.
B) A for loop.
C) A program.
D) The main() function.
Answer: A
BCPL was developed in the year ___________.
A) 1967.
B) 1964.
C) 1962.
D) 1960.112-C Programming
Answer: A
_______ convert from high-level language to machine language
A) Compiler.
B) Interpreter.
C) Assembler.
D) Loader.
Answer: A
Which of the following is not a rule for constructing integer constant.
A) An integer constant must have atleast one digit
B) It must have a decimal point
C) If no sign precedes an integer constant, it is assumed to be positive.
D) No commas, or blanks are allowed within an integer constant.
Answer: A
Which of the following is not a character constant
A) A.
B) 5.
C) @.
D) Raju .
Answer: B
Which of the following is not correct?
A) An arithmetic operation between an integer and integer yields an integer
result.
B) An operation between real and real yield a integer
C) An operation between integer and real yields a real result
D) Integer is first promoted to real and then operation is performed.
Answer: D
The meaning of the expression x<=y is_____________.
A) X is equal to y.
B) X is not equal to y.
C) X is greater than or equal to y.
D) X is less than or equal to y .
Answer: B
Which of the following expression is correct?
A) expression1? expression2: expression3.
B) expression1:expression2?expression3.
C) expression1*expression2?expression3.
D) expression1:expression2/expression3.
Answer: D
What will be the output of the following?
#include<stdio.h>
Void main()
{
Int x;
X=5;
X=10;
Printf(x=%d,x);
}112-C Programming
A) 5.
B) 10 .
C) 15.
D) 20.
Answer: A
What is the result of the following expression: i=2*3/4+4/4+8-2+5/8?
A) 5.
B) 8 .
C) 10.
D) 15.
Answer: B
What is the output of the following?
#include<stdio.h>
main()
{
int a=300,b,c;
if(a>=400)
{
b=300;
}
c=200;
printf(%d%d,b,c);
}
A) 300.
B) 200.
C) 12803200.
D) 100.
Answer: B
What is the output of the following program?
#include<stdio.h>
void main()
{
int x=3, y=5;
if(x==3)
printf(%d,x);
else
printf(%d,y);
}
A) 3.
B) 2020.
C) 5.
D) 222.
Answer: C
Predict the output or error(s) for the following:112-C Programming
void main()
{
int const * p=5;
printf("%d",++(*p));
}
A) 5.
B) Compiler error: Cannot modify a constant value.
C) Garbage value.
D) 1248.
Answer: C
What will be the output of the following program?
main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
A) 5.
B) 5 4 3 2 1.
C) 3 2 3.
D) Compiler Error.
Answer: B
What will be the output for the following code?
enum control
{
On, off, neutral
};
PRINTF (%d, off);
A) Compilation error
B) Execution error
C) 5
D) 1
Answer: A
Predict the output of the following program.
main()
{
extern int i;
i=20;
printf("%d",i);
}
A) 20.
B) Compiler Error.
C) Linker Error.
D) Garbage value.
Answer: A112-C Programming
Which of the following is the correct output for the program given below
?
#include<stdio.h>
void main()
{
int i=5;
while(i-- >= 0) printf(%d,i);
i=5;
while(i-- >=0) printf(%i,i);
while(i-- >=0) printf(%d, i);
}
A) 4 3 2 1 0 -1 4 3 2 1 0 -1.
B) 5 4 3 2 1 0 5 4 3 2 1 0.
C) Error.
D) 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0.
Answer: A
Predict the output of the following program.
main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
A) one.
B) two.
C) three .
D) four.
Answer: C
Which of the following is not a user-defined data type?
struct book
{
Char name[10];
Float price;
Int pages;
}
A) long int i=23.5
B) enum day {Sun, Mon, Tue, Wed};
C) union a
{
112-C Programming
Int I;
Char ch[ 2];
} ;
D) none of these.
Answer: B
Which of the following definition is correct?
A) int length;
B) char int;
C) int long;
D) float double;
Answer: A
In the program given below, point out the error, if any, in the for loop
.
#include<stdio.h>
void main()
{
int i=1;
for(;;)
{
printf(%d,i++);
if(i>10)
break;
}
}
A) The condition in the for loop is a must.
B) The two semicolons should be dropped.
C) The for loop should be replaced by while loop.
D) No error.
Answer: D
Which of the following statements are correct about the program given be
low?
#include<stdio.h>
void main()
{
int x=30, y=40;
if(x==y)
printf(x is equal to y);
elseif(x>y)
printf(x is greater than y);
elseif(x<y)
printf(x is less than y);
}
A) Error: Statement Missing
B) Error: Expression syntax
C) Error: Lvalue required
D) Error: Rvalue required
Answer: A
Which of the following is not a logical operator?112-C Programming
&.
&&.
||.
!.
Answer: A