Welcome Guest

C Questions for SAMSUNG

Q. No. :1
Question :Assuming a short is two bytes long, what will be printed by the above code?
short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} };
printf( "%d ", sizeof( testarray ) );
A :
It will not compile because not enough initializers are given.
B :
6
C :
12
D :
24
Answer: D
Q. No. :2
Question :What will the output?
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 ", i);
A :
i = 5
B :
i = 8
C :
i = 9
D :
i = 10
Answer: A
Q. No. :3
Question :What will the sample code produce when executed?
void myFunc (int x)
{
if (x > 0)
myFunc(--x);
printf("%d, ", x);
}
int main()
{
myFunc(5);
return 0;
}
A :
1, 2, 3, 4, 5, 5,
B :
4, 3, 2, 1, 0, 0,
C :
0, 0, 1, 2, 3, 4
D :
0, 1, 2, 3, 4, 5,
Answer: C
Solution
Q. No. :4
Question :What will be the output?
main(){
char c='a';
printf("%d %d", sizeof(c),sizeof('a'));
}
A :
1 1
B :
4 4
C :
1 4
D :
1 2
Answer: C
Solution
Q. No. :5
Question :What does the operation produce?
11 ^ 5
A :
1
B :
6
C :
8
D :
14
Answer: D
Solution
Q. No. :6
Question : What will be the output of the code snippet if compiler is considered to be 32 bit?
struct ptr
{
int a;
char b;
int *p;
union xy
{
int x;
char y;
};
}abc;
printf("%d",sizeof(abc));
A :
5
B :
7
C :
8
D :
10
Answer: B
Q. No. :7
Question :What will happen when the program below is compiled and executed?
#include <stdio.h>
int i;
void increment( int i )
{
i++;
}

int main()
{
for( i = 0; i < 10; increment( i ) )
{
}
printf("i=%d ", i);
return 0;
}
A :
It will not compile.
B :
It will print out: i=10
C :
It will print out: i=11
D :
It will loop indefinitely
Answer: D
Q. No. :8
Question :What will be the output of the program ?
#include< stdio.h >
void fun(void *p);
int i;
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d ", **q);
}
A :
Error: cannot convert from void** to int**
B :
Garbage value
C :
0
D :
No output
Answer: C
Q. No. :9
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. :10
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. :11
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. :12
Question :If the size of integer is 4bytes. What will be the output of the program?
#include< stdio.h >

int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d ", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
A :
10, 2, 4
B :
20, 4, 4
C :
16, 2, 2
D :
20, 2, 2
Answer: B
Q. No. :13
Question :Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?
A :
memcpy()
B :
memset()
C :
strncpy()
D :
memmove()
Answer: D
Q. No. :14
Question :What will print when the sample code below is executed?
char* myFunc (char *ptr)
{
ptr += 3;
return (ptr);
}
int main()
{
char *x, *y;
x = "HELLO";
y = myFunc (x);
printf ("y = %s ", y);
return 0;
}
A :
y = HELLO
B :
y = ELLO
C :
y = LLO
D :
y = LO
Answer: D
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 :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. :17
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. :18
Question :What is a proper method of opening a file for writing as binary file?
A :
FILE *f = fwrite( "test.bin", "b" );
B :
FILE *f = fopen( "test.bin", "wb" );
C :
FILE *f = fwriteb( "test.bin" );
D :
FILE *f = fopen( "test.bin", "bw" );
Answer: B
Solution
Q. No. :19
Question :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.
C :
It automatically increments the variable when used.
D :
It automatically initializes a variable to NULL.
Answer: B
Q. No. :20
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. :21
Question :What will be the output of the program?
#include< stdio.h >

int main()
{
printf("%d > > %d %d > > %d "4 > > 1, 8 > > 1);
return 0;
}
A :
4 1 8 1
B :
4 >> 1 8 >> 1
C :
2 >> 4 Garbage value >> Garbage value
D :
2 4
Answer: C
Q. No. :22
Question :Point out the error in the program?
#include< stdio.h >
void modify(struct emp *);
struct emp
{
char name[20];
int age;
};
int main()
{
struct emp e = {"Sanjay", 35};
modify(&e);
printf("%s %d", e.name, e.age);
return 0;
}
void modify(struct emp *p)
{
strupr(p > name);
p ->age=p->age+2;
}
A :
Error: in structure
B :
Error: in prototype declaration unknown struct emp
C :
No error
D :
None of above
Answer: B
Solution
Q. No. :23
Question :What number will z in the sample code below contain?
int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;
A :
5
B :
6
C :
10
D :
11
Answer: C
Solution
Q. No. :24
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
Q. No. :25
Question :What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 1 2 3
/* myprog.c */
#include< stdio.h >
#include

int main(int argc, char **argv)
{
int i, j=0;
for(i=0; i<argc; i++)
j = j+atoi(argv[i]);
printf("%d ", j);
return 0;
}
A :
123
B :
6
C :
Error
D :
"123"
Answer: B
Q. No. :26
Question :If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include< stdio.h >
int main()
{
unsigned int m = 32;
printf("%x ", ~m);
return 0;
}
A :
ffff
B :
0000
C :
ffdf
D :
ddfd
Answer: C
Q. No. :27
Question :What will be the output of the program?
#include< stdio.h >
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d ", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
A :
4,4
B :
3,3
C :
6,6
D :
12,12
Answer: C
Q. No. :28
Question :int a [8] = { 0, 1, 2, 3 };
The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
A :
Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
B :
The remaining elements are initialized to zero(0)
C :
It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized
D :
As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.
Answer: B
Q. No. :29
Question :What will be the output of the program?
#include< stdio.h >
#include< math.h >
int main()
{
printf("%f ", sqrt(36.0));
return 0;
}
A :
6.0
B :
6
C :
6.000000
D :
Error: Prototype sqrt() not found
Answer: C
Solution
Q. No. :30
Question :The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?
struct node *nPtr, *sPtr; /* pointers for a linked list. */
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{
free(nPtr);
}
A :
It will work correctly since the for loop covers the entire list.
B :
It may fail since each node "nPtr" is freed before its next address can be accessed.
C :
In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".
D :
The loop will never end.
Answer: B