Welcome Guest

C Questions for ARICENT

Q. No. :1
Question :The following program
main()
{
int i=2;
{ int i=4; j=5;
printf("%d%d",i , j );
}
printf("%d%d", i , j);
}
A :
will not compile successfully
B :
prints 4525
C :
prints 2525
D :
None
Answer: A
Solution
Q. No. :2
Question :What will be the output of the program ?
#include< stdio.h >
int main()
{
char str1[] = "Hello";
char str2[] = "Hello";
if(str1 == str2)
printf("Equal ");
else
printf("Unequal ");
return 0;
}
A :
Equal
B :
Unequal
C :
Error
D :
None
Answer: B
Solution
Q. No. :3
Question :The following program
main()
{ int abc();
abc();
(*abc)();
}
int abc()
{ printf("come"); }
A :
results in a compilation error
B :
prints come come
C :
results in a run time error
D :
prints come come
Answer: B
Solution
Q. No. :4
Question :What will be the output of the program?
#include< stdio.h >
int main()
{
int fun(int);
int i = fun(10);
printf("%d ", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
A :
9
B :
10
C :
11
D :
8
Answer: A
Solution
Q. No. :5
Question :The following code fragment
int x,y = 2,z,a;
x = (y *= 2) + (z = a = y);
printf("%d",x);
A :
prints 8
B :
prints 6
C :
prints 6 or 8 d3epending on the compiler implementation
D :
is syntactically wrong
Answer: C
Solution
Q. No. :6
Question :What will be the output of the program?
#include< stdio.h >
int reverse(int);
int main()
{
int no=5;
reverse(no);
return 0;
}
int reverse(int no)
{
if(no == 0)
return 0;
else
printf("%d,", no);
reverse (no--);
}
A :
Print 5, 4, 3, 2, 1
B :
Print 1, 2, 3, 4, 5
C :
Print 5, 4, 3, 2, 1, 0
D :
Infinite loo
Answer: D
Solution
Q. No. :7
Question :What will be the output of the program ?
#include< stdio.h >

int main()
{
int a=250;
printf("%1d ", a);
return 0;
}
A :
1250
B :
2
C :
50
D :
250
Answer: D
Solution
Q. No. :8
Question :Which of the following statements are correct about the program below?
#include< stdio.h >

int main()
{
char str[20], *s;
printf("Enter a string ");
scanf("%s", str);
s=str;
while(*s != '\0')
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf("%s",str);
return 0;
}
A :
The code converts a string in to an integer
B :
The code converts lower case character to upper case
C :
The code converts upper case character to lower case
D :
Error in code
Answer: B
Solution
Q. No. :9
Question :Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?
#include< stdio.h >
#include
#define MAXROW 3
#define MAXCOL 4

int main()
{
int (*p)[MAXCOL];
p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p));
return 0;
}
A :
56 bytes
B :
128 bytes
C :
24 bytes
D :
12 bytes
Answer: C
Q. No. :10
Question :The following statements:
for(i=3;i<15;i+=3)
{
printf("%d",i);
++i;
}

will result in the printing of
A :
3 6 9 12
B :
3 6 9 12 15
C :
3 7 11
D :
3 7 11 15
Answer: C
Solution
Q. No. :11
Question :What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?

#include< stdio.h >
int main()
{
void fun();
fun();
printf(" ");
return 0;
}
void fun()
{
char c;
if((c = getchar())!= ' ')
fun();
printf("%c", c);
}
A :
abc abc
B :
bca
C :
Infinite loop
D :
cba
Answer: D
Solution
Q. No. :12
Question :Consider the following statement:
#define hypoteneuse(a,b) sqrt(a*a + b*b);

The macro-call hypotenuse(a + 2,b + 3);
A :
finds the hypotenuse of a triangle with sides a + 2 and b + 2.
B :
finds the square root of (a+2)2 + (b + 3)2
C :
is invalid
D :
finds the square root of 3*a + 4*b + 5
Answer: D
Solution
Q. No. :13
Question :The for loop
for(i=0;i<10;++i)
printf("%d", i & 1);

prints
A :
0101010101
B :
0111111111
C :
0000000000
D :
1111111111
Answer: A
Solution
Q. No. :14
Question :Which of the following function is correct that finds the length of a string?
A :
int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

{ length++; s++; }

return (length);

}

B :
int xstrlen(char s)

{

int length=0;

while(*s!='\0')

length++; s++;

return (length);

}

C :
int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

length++;

return (length);

}

D :
int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

s++;

return (length);

}

Answer: A
Solution
Q. No. :15
Question :What will be the output of the program ?
#include<stdio.h>

int main()
{
FILE *ptr;
char i;
ptr = fopen("myfile.c", "r");
while((i=fgetc(ptr))!=NULL)
printf("%c", i);
return 0;
}
A :
Print the contents of file "myfile.c"
B :
Print the contents of file "myfile.c" upto NULL character
C :
Infinite loop
D :
Error in program
Answer: C
Solution
Q. No. :16
Question :The output of the following program is
main()
{
int a=5, b=2;
printf("%d", a+++b);}
A :
Syntax error
B :
7
C :
8
D :
None
Answer: B
Solution
Q. No. :17
Question :What is the output of the following program segment?
void max(int x, int y, int m)
{ if(x>5) m=x;
else m=y;}
int main()
{
int i=20, j=5, k=0;
max(i,j,k);
printf("%d",k);
}
A :
5
B :
20
C :
0
D :
None
Answer: C
Solution
Q. No. :18
Question :What will be the output of the program ?
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf("%d ", sizeof(arr)/sizeof(arr[0]));
return 0;
}
A :
5
B :
4
C :
6
D :
7
Answer: B
Solution
Q. No. :19
Question :The following program
main()
{
printf("tim");
main();
}
A :
is illegal
B :
keeps on printing tim
C :
prints tim once
D :
none
Answer: B
Solution
Q. No. :20
Question :What will be the output of the program ?
#include< stdio.h >

int main()
{
static int arr[] = {0, 1, 2, 3, 4};
int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int **ptr=p;
ptr++;
printf("%d, %d, %d ", ptr-p, *ptr-arr, **ptr);
*ptr++;
printf("%d, %d, %d ", ptr-p, *ptr-arr, **ptr);
*++ptr;
printf("%d, %d, %d ", ptr-p, *ptr-arr, **ptr);
++*ptr;
printf("%d, %d, %d ", ptr-p, *ptr-arr, **ptr);
return 0;
}
A :
0, 0, 0

1, 1, 1

2, 2, 2

3, 3, 3
B :
1, 1, 2

2, 2, 3

3, 3, 4

4, 4, 1
C :
1, 1, 1

2, 2, 2

3, 3, 3

3, 4, 4
D :
0, 1, 2

1, 2, 3

2, 3, 4

3, 4, 5
Answer: C
Q. No. :21
Question :What will be the output of the program?
#include< stdio.h >
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d ", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A :
Print 10
B :
Print 20
C :
Print 1
D :
Compile error
Answer: D
Solution
Q. No. :22
Question : The following program fragment
if(2<1) ; else x=(2<0)? printf("one") : printf("four"); printf("%d",x);
A :
prints nothing
B :
results in a syntax error
C :
prints four1
D :
prints four4
Answer: D
Solution
Q. No. :23
Question :What will be the output of the program ?
#include< stdio.h >
void swap(char *, char *);
int main()
{
char *pstr[2] = {"Hello", "GPLgtests"};
swap(pstr[0], pstr[1]);
printf("%s %s", pstr[0], pstr[1]);
return 0;
}
void swap(char *t1, char *t2)
{
char *t;
t=t1;
t1=t2;
t2=t;
}
A :
GPLgtests Hello
B :
Address of "Hello" and "GPLgtests"
C :
Hello GPLgtests
D :
Gello  HPLgtests
Answer: C
Solution
Q. No. :24
Question :If the size of pointer is 4 bytes then What will be the output of the program ?
#include< stdio.h >
int main()
{
char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
printf("%d, %d", sizeof(str), strlen(str[0]));
return 0;
}
A :
22, 4
B :
25, 5
C :
24, 5
D :
20, 2
Answer: C
Solution
Q. No. :25
Question :What will be the output of the program?
#include< stdio.h >

int main()
{
int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
int *p, *q;
p = &arr[1][1][1];
q = (int*) arr;
printf("%d, %d ", *p, *q);
return 0;
}
A :
8, 10
B :
8, 2
C :
8, 1
D :
Garbage vlaues
Answer: A
Q. No. :26
Question :what will be the output ?
#include< stdio.h >
main()
{
int i=0;
switch(i)
case 0 : i++;
case 1 : i++;
case 2 : i++;
default: i++;
printf("%d",i);
}
A :
0
B :
1
C :
2
D :
4
Answer: D
Solution
Q. No. :27
Question :What will be the output of the program if it is executed like below?
cmd> sample
/* sample.c */
#include< stdio.h >
int main(int argc, char **argv)
{
printf("%s ", argv[argc-1]);
return 0;
}
A :
0
B :
sample
C :
samp
D :
No output
Answer: B
Q. No. :28
Question :What will be the output of the program?
#include< stdio.h >
int X=40;
int main()
{
int X=20;
printf("%d ", X);
return 0;
}
A :
20
B :
40
C :
Error
D :
No output
Answer: A
Solution
Q. No. :29
Question :What 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.
Answer: C
Solution
Q. No. :30
Question :Macro FILE is defined in
A :
stdio.h
B :
conio.h
C :
ctype.h
D :
string.h
Answer: A
Q. No. :31
Question :If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
A :
'.'
B :
'*'
C :
'&'
D :
'->'
Answer: D
Q. No. :32
Question :In the following program where is the variable a getting defined and where it is getting declared?
#include< stdio.h >
int main()
{
extern int a;
printf("%d ", a);
return 0;
}
int a=20;
A :
extern int a is declaration, int a = 20 is the definition
B :
int a = 20 is declaration, extern int a is the definition
C :
int a = 20 is definition, a is not defined
D :
a is declared, a is not defined
Answer: A
Solution
Q. No. :33
Question :If the size of an integer is 4 bytes, What will be the output of the program ?
#include< stdio.h >
#include

int main()
{
printf("%d ", strlen("123456"));
return 0;
}
A :
6
B :
12
C :
7
D :
2
Answer: A
Solution
Q. No. :34
Question :How will you print \0 on the screen?
A :
printf("\b");
B :
echo "\\b";
C :
printf('\b');
D :
printf("\\b");
Answer: D
Solution
Q. No. :35
Question :What do the following declaration signify?
int *f();
A :
f is a pointer variable of function type.
B :
f is a function returning pointer to an int.
C :
f is a function pointer.
D :
f is a simple declaration of pointer variable.
Answer: B
Q. No. :36
Question :What function should be used to free the memory allocated by calloc() ?
A :
dealloc();
B :
malloc(variable_name, 0)
C :
free();
D :
memalloc(variable_name, 0)
Answer: C
Q. No. :37
Question :What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include< stdio.h >

int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf("%u, %u, %u ", a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}

A :
448, 4, 4
B :
520, 2, 2
C :
1006, 2, 2
D :
Error
Answer: C
Q. No. :38
Question :What will be the output of the program?
#include< stdio.h >
int main()
{
int x, y, z;
x=y=z=1;
z = ++x || ++y && ++z;
printf("x=%d, y=%d, z=%d ", x, y, z);
return 0;
}
A :
x=2, y=1, z=1
B :
x=2, y=2, z=1
C :
x=2, y=2, z=2
D :
x=1, y=2, z=1
Answer: A
Solution
Q. No. :39
Question :What will be the output of the program ?
#include< stdio.h >
int main()
{
int i=32, j=0x20, k, l, m;
k=i|j;
l=i&j;
m=k^l;
printf("%d, %d, %d, %d, %d ", i, j, k, l, m);
return 0;
}
A :
0, 0, 0, 0, 0
B :
0, 32, 32, 32, 32
C :
32, 32, 32, 32, 0
D :
32, 32, 32, 32, 32
Answer: C
Solution
Q. No. :40
Question :What will be the output of the program?
#include< stdio.h >
int main()
{
int x = 10, y = 20;
if(!(!x) && x)
printf("x = %d ", x);
else
printf("y = %d ", y);
return 0;
}
A :
y =20
B :
x = 0
C :
x = 10
D :
x = 1
Answer: C
Solution
Q. No. :41
Question :What will be the output of the program?
#include< stdio.h >
#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()
{
int i=10, j=5, k=0;
k = MAN(++i, j++);
printf("%d, %d, %d ", i, j, k);
return 0;
}
A :
12, 6, 12
B :
11, 5, 11
C :
11, 5, Garbage
D :
12, 6, Garbage
Answer: A
Solution
Q. No. :42
Question :What will be the output of the program?
#include< stdio.h >
int main()
{
float a=0.7;
if(a < 0.7)
printf("C ");
else
printf("C++ ");
return 0;
}
A :
C
B :
C++
C :
Compiler error
D :
None
Answer: A
Solution
Q. No. :43
Question :What does the following declaration mean?
int (*ptr)[10]
A :
ptr is array of pointers to 10 integers
B :
ptr is a pointer to an array of 10 integers
C :
ptr is an array of 10 integers
D :
ptr is an pointer to array
Answer: B
Solution
Q. No. :44
Question :Which of the following statements are correct about the below C-program?
#include< stdio.h >
int main()
{
int x = 10, y = 100%90, i;
for(i=1; i<10; i++)
if(x != y);
printf("x = %d y = %d ", x, y);
return 0;
}

1 : The printf() function is called 10 times.
2 : The program will produce the output x = 10 y = 10
3 : The ; after the if(x!=y) will NOT produce an error.
4 : The program will not produce output.
A :
1
B :
2, 3
C :
1, 4
D :
2, 3, 4
Answer: B
Q. No. :45
Question :The library function used to reverse a string is
A :
strstr()
B :
strrev()
C :
revstr()
D :
strreverse()
Answer: B
Solution
Q. No. :46
Question :What will be the output of the program?
#include< stdio.h >
#define SQR(x)(x*x)

int main()
{
int a, b=3;
a = SQR(b+2);
printf("%d ", a);
return 0;
}
A :
25
B :
11
C :
Error
D :
Garbage value
Answer: B
Solution