Welcome Guest

C Questions for AMDOCS

Q. No. :1
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. :2
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. :3
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. :4
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. :5
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. :6
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. :7
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. :8
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. :9
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. :10
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. :11
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. :12
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. :13
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. :14
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. :15
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. :16
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. :17
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. :18
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. :19
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. :20
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. :21
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. :22
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. :23
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