wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Program

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

What is the Format specifier used to print a String or Character array in C Printf or Scanf function.?

a)

%c

b)

%C

c)

%s

d)

%w

2.

Find the Output for the Following code:

#include <stdio.h>

void main()

{

printf("""Hello World""");

}

a)

""Hello World""

b)

Hello World

c)

"Hello World"

d)

error

3.

How do you convert this char array to string.?

char str[]={'g','l','o','b','y'};

A) str[5] = 0;

B) str[5] = '\0'

C) str[]={'g','l','o','b','y','\0'};

D) All the above

a)

D

b)

A

c)

B

d)

C

4.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int c=5,s=0;

while(c<10)

{

c=c+1;

s=s-2;

}

printf("%d",s);

return 0;

}

a)

10

b)

5

c)

-10

d)

0

5.

Find how many stars will be printed for below code:

#include <stdio.h>

int main()

{

int a=0;

while(a<25){

if(a>0 || a<=10)

{

printf("*");

}

else if(a>10 || a<=20)

{

printf("*");

}

else if(a>20 || a<=30)

{

printf("*");

}

a++;

}

return 0;

}

a)

35 stars

b)

25 stars

c)

30 stars

d)

20 stars

6.

What is the maximum length of a C String.?

A) 32 characters

B) 64 characters

C) 256 characters

D) None of the above

a)

A

b)

B

c)

C

d)

D

7.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int a=0,b=1;

while(a<=10)

{

printf("%d",a);

a=a+2;

a=a-b;

}

return 0;

}

a)

012345678910

b)

12345678910

c)

0123456789

d)

error

8.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int i=1;

for(int i=1;i<=5;i++);

{

printf("%d ",i);

}

printf("Hello");

return 0;

}

a)

1 Hello

b)

12345 Hello

c)

Hello

d)

No ouput

9.

Choose a correct C Statement about Strings.

A) PRINTF is capable of printing a multi word string.

B) PUTS is capable of printing a multi word string.

C) GETS is capable of accepting a multi word string from console or command prompt

D) All the above

a)

D

b)

C

c)

B

d)

A

10.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int a=1;

do{

printf("%d",a);

}while(a);

return 0;

}

a)

1

b)

No output

c)

infinity

d)

error

11.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int a=1,b=0;

do{

printf("Hello\n");

a=a+2;

b=a-a;

}while(b>0);

return 0;

}

a)

Hello

b)

infinity

c)

Hello

Hello

d)

Hello

Hello

Hello

Hello

12.

In C, function primarily used for?

A. Decision making

B. Variable declaration

C. Code organization and reusability

D. Printing output

a)

C

b)

D

c)

A

d)

B

13.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int a=1;

switch(a);

{

case 1:

printf("One");

break;

case 2:

printf("Two");

break;

default:

printf("Enter <2");

break;

}

return 0;

}

a)

Error

b)

One

c)

Two

d)

Enter <2

14.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int arun=100,vijay=200;

int a=10,b=20;

int

temp=arun;

arun=vijay;

vijay=temp;

while(a<b && b>a)

{

if(arun==150 && vijay==150)

{

printf("* ");

break;

}

else

{

arun=arun-vijay+50;

vijay=arun;

continue;

printf("* * ");

}

}

printf("%d %d",arun,vijay);

return 0;

}

a)

* 150 150

b)

150 150 *

c)

150 150

d)

*150150

15.

What are the types of functions in C Language?

a) Library Functions

b) User Defined Functions

c) Both Library and User Defined

d) None of the above

a)

A

b)

C

c)

D

d)

B

16.

Find the Output for the Following code:

#include <stdio.h>

int main()

{

int arr[20]={10,20,30,40,50};

int i=0;

int *ptr=arr;

i+=3;

printf("%d",*(ptr+i));

return 0;

}

a)

10

b)

20

c)

30

d)

40

17.

Find the Output for the Following code:

#include <stdio.h>

#include<string.h>

int main()

{

char str[]={'h','e','l','l','o','\0'};

int length=strlen(str);

char *ptr=str;

for(int i=0;i<=length-1;i++)

{

if(str[i]==str[i+1])

{

printf("I found Duplicate letter when i is = %d",i);

}

continue;

}

return 0;

}

a)

1

b)

2

c)

3

d)

Null

18.

Every C Program should contain which function?

a) printf()

b) show()

c) scanf()

d) main()

a)

D

b)

A

c)

B

d)

C

19.

Find the Output for the Following code:

#include <stdio.h>

void add(int a,int b)

{

int c=a+b;

printf("%d\n",c);

}

int main()

{

int a=10,b=20;

add(a,b);

a=5,b=5;

add(a,b);

return 0;

}

a)

30

10

b)

20

10

c)

20

30

d)

10

30

20.

Choose a corrects statement about C language function arguments.

a) Number of arguments should be same when sending and receiving

b) Type of each argument should match exactly

c) Order of each argument should be same

d) All the above

a)

A

b)

B

c)

C

d)

D