wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Test in C Language

Total questions: 10

Worksheet time: 30mins

Name
Class
Date
1.

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 array is stored starting from memory address 0,the address of

a[40][50] is

a)

4040

b)

4050

c)

5040

d)

5050

2.

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

3.

Consider the following C declaration :

struct {

short s[5]

union{

float y;

long z;

}u;

}t;

Assuming 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 alignmenmt considerations, is :

a)

22 bytes

b)

18 bytes

c)

14 bytes

d)

10 bytes

4.

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

char inchar='A';

switch(inchar)

{

case\\\'A\\\'n:

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

5.

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);

}

a)

x+y using repeated subtraction

b)

x mod y using repeated subtraction

c)

the greatest common divisior of x and y

d)

the least common multiple of x and y

6.

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 return by f(1) is

a)

5

b)

6

c)

7

d)

8

7.

Consider the following C function :

void swap(int a,int b)

{

int temp;

temp=a;

a=b;

b=temp;

}

In order to exchange the value of two variable 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

8.

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

9.

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

10.

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 value of foo(513,2)

a)

9

b)

8

c)

5

d)

2