wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming in C Week 4

Total questions: 89

Worksheet time: 2hrs 29mins

Name
Class
Date
1.

What is the output of C Program.?

int main()

{

int k;

for(;;)

{

printf("TESTING\n");

break;

}

return 0;

}

a)

No Output

b)

TESTING

c)

Compiler error

d)

None of the above

2.

int main()


{


char arr[7]="Network";


printf("%s", arr);


return 0;


}

a)

Network

b)

N

c)

Garbage Value

d)

Compilation error

3.

We can initialize a two-dimensional array in the form of ---------

a)

Searching

b)

increment

c)

matrix

d)

none of these

4.

The two dimensional array is

a)

int

b)

struct

c)

matrix

d)

none of these

5.

---------- and ------------ are the two frequent operations on arrays.

a)

Searching and sorting

b)

Decrementing and decrementing

c)

Searching and incrementing

d)

none of these

6.

Structure keyword is -------------

a)

struct

b)

array

c)

main

d)

none of these

7.

Which is the only function all C programs must contain?

a)

start()

b)

system()

c)

printf()

d)

main()

8.
How would you round off a value from 1.66 to 2.0?
a)
ceil(1.66)
b)
floor(1.66)
c)
roundup(1.66)
d)
roundto(1.66)
9.
How would you round off a value from 1.66 to 2.0?
a)
ceil(1.66)
b)
floor(1.66)
c)
roundup(1.66)
d)
roundto(1.66)
10.
Point out the error in the following program 
a)
No error
b)
display() doesn't get invoked
c)
display() is called before it is defined
d)
None of these
11.
Point out the error in the following program
a)
Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.
b)
Program terminates abnormally.
c)
No error
d)
None of these.
12.
In which order do the following gets evaluated
1.Relational
2.Arithmetic
3.Logical
4.Assignment
a)
2134
b)
1234
c)
4321
d)
3214
13.
What is (void*)0?
a)
Representation of NULL pointer
b)
Representation of void pointer
c)
Error
d)
None of above
14.
Point out the compile time error in the program given below.
a)
Error: invalid assignment for x
b)
Error: suspicious pointer conversion
c)
No error
d)
None of above
15.
If the two strings are identical, then strcmp() function returns
a)
-1
b)
1
c)
0
d)
yes
16.
How will you print \n on the screen?
a)
printf("\n");
b)
echo "\\n";
c)
printf('\n');
d)
printf("\\n");
17.
What will be the output of the program?
a)
128
b)
Garbage value
c)
Error
d)
0
18.
In C, if you pass an array as an argument to a function, what actually gets passed?
a)
Value of elements in array
b)
First element of the array
c)
Base address of the array
d)
Address of the last element of array
19.
What is the similarity between a structure, union and enumeration?
a)
All of them let you define new values
b)
All of them let you define new data types
c)
All of them let you define new pointers
d)
All of them let you define new structures
20.
Which of the following function is used to find the first occurrence of a given string in another string?
a)
strchr()
b)
strrchr()
c)
strstr()
d)
strnset()
21.
Which statement will you add in the following program to work it correctly?
a)
#include<conio.h>
b)
#include<math.h>
c)
#include<stdlib.h>
d)
#include<dos.h>
22.
We want to round off x, a float, to an int value, The correct way to do is
a)
y = (int)(x + 0.5)
b)
y = int(x + 0.5)
c)
y = (int)x + 0.5
d)
y = (int)((int)x + 0.5)
23.
Associativity has no role to play unless the precedence of operator is same.
a)
True
b)
False
24.
Functions cannot return more than one value at a time
a)
True
b)
False
25.
In C all functions except main() can be called recursively.
a)
True
b)
False
26.
The modulus operator cannot be used with a long double.
a)
True
b)
False
27.

The process of removing a bug is known as

a)

Debugging

b)

Compilation

c)

Executing

d)

Running

28.

How many choices are possible when using a single if-else statement?

a)

1

b)

2

c)

3

d)

4

29.

What does the following code fragment write to the monitor?

a)

Under

b)

Over

c)

Under the limit

d)

Over the limit

30.

What does the following code fragment write to the monitor?

a)

Under

b)

Over

c)

Under the limit.

d)

Over the limit.

31.

What does the following code fragment write to the monitor?

a)

You win

b)

You lose

c)

You win the prize.

d)

You lose the prize.

32.

What does the following code fragment write to the monitor?

a)

You win

b)

You lose

c)

You win the prize.

d)

You lose the prize.

33.

In if-else, else block execute when

a)

"if expression" return true

b)

"if expression" return false

c)

"else expression" return true

d)

"else expression" return false

34.

Which of the following is the boolean operator for logical-AND?

a)

&

b)

&&

c)

|

d)

||

35.

Which is correct with respect to size of the data types?

a)

char > int > float

b)

int > char > float

c)

char < int < double

d)

double > char > int

36.

#include <stdio.h>

int main()

{

signed char chr;

chr = 128;

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

return 0;

}

a)

128

b)

0

c)

-128

d)

Garbage Value

37.

string[] animal = new string[]{"lion", "tiger","zebra","elephant"};

What is the value of animal[2];

a)

lion

b)

tiger

c)

zebra

d)

elephant

38.
Which one is a function prototype?
a)
void function ();
b)
function ();
c)
void function [];
d)
() function { };
39.

Can we declare function inside structure of C Programming?

a)

Yes

b)

No

c)

Depends on Compiler

d)

Yes but run time error

40.

What is output of below code?


void main()

{

char name[]="Cppbuz";

int len;

int size;

len = strlen(name);

size = size_of(name);

printf("%d,%d",len,size);

}

a)

6,6

b)

6,7

c)

7,7

d)

0,0

41.

What is meaning of below lines?

void sum (int, int);

a)

sum is a function which takes two int arguments and returns void

b)

sum is function which takes int arguments

c)

it will produce compilation error

d)

Can't comment.

42.

What will print?

a)

s

b)

m

c)

d

d)

e

43.
a)

0

b)

1

c)

5

d)

10

44.
a)

0

b)

6

c)

100

d)

none of these

45.
a)

0

b)

1

c)

10

d)

100

46.

What is printed?

a)

nothing

b)

0

c)

6

d)

100

47.

What will print?

a)

0

b)

1

c)

100

d)

101

48.

What will print?

a)

0

b)

1

c)

100

d)

101

49.

What will print?

a)

10

b)

20

c)

30

d)

40

50.

What will print?

a)

20

b)

40

c)

60

d)

50

51.

Determine the value of the expression using integer arithmetic:

6 * 9 % 3 / 2

a)

2

b)

0

c)

18

52.

Which line of code is correct for the statement:

Add 1 variable to x.

a)

x++;

b)

x+1

c)

x+x

53.

What is the abbreviated way to write this assignment statement:

total=total+num;

a)

t=t+n;

b)

total+=num

c)

total=(total+num)

54.

What will be printed on the screen from this fragment:

int num=0;

printf("%d", ++num)

a)

0

b)

1

c)

2

55.

What is the output of C Program.?

int main()

{

int k;

for(;;)

{

printf("TESTING\n");

break;

}

return 0;

}

a)

No Output

b)

TESTING

c)

Compiler error

d)

None of the above

56.

int main()


{


int a = 10, b = 25;


a = b++ + a++;


b = ++b + ++a;


printf("%d %d n", a, b);


}

a)

36 64

b)

35 62

c)

36 63

d)

30 28

57.

What will be output of the following c program?

#include<stdio.h>

int main()

{

int max-val=100;

int min-val=10;

int avg-val;

avg-val = max-val + min-val / 2;

printf("%d",avg-val);

}

a)

55

b)

105

c)

60

d)

Compilation error

58.

What is the output of the following printf


printf("%d",34+24/12%3*5/2-4);

a)

35

b)

-2

c)

34

d)

38

59.

Which of the following ternary operator is correct to findout biggest of 3 numbers:

a)

c>a?(c>b?c:b):(a>b?a:b)

b)

b<a?(a>c?a:c):(b<c?b:c)

c)

c<b?(b<a?b:a):(c<a?c:a)

d)

a<b?(b>c?b:c):(a<c?c:a)

60.

What is the output of the following printf:


int a=10,b=8;

printf("%d",a+~b);

a)

1

b)

18

c)

19

d)

2

61.

What is the output of the following printf:


printf("%d",10<400>300>40);

a)

0

b)

1

c)

Error

d)

400

62.

Which of the function is more appropriate for reading a multi-word string?

a)

puts()

b)

printf()

c)

scanf()

d)

gets()

63.

Equivalent of switch statement

a)

If

b)

if-else

c)

elseif ladder

d)

while

64.

What is the output of C Program.?

int main()

{

int a=5;

while(a=123)

{

printf("RABBIT\n");

break;

}

printf("GREEN");

return 0;

}

a)

GREEN

b)

RABBIT GREEN

c)

RABBIT is printed unlimited number of times.

d)

Compiler error.

65.

#include<stdio.h>

int main()

{

function();

return 0;

}

void function()

{

printf("Function in C is awesome");

}

a)

Function in C is awesome

b)

No output

c)

Runtime Error

d)

Compilation Error

66.

What will be the output of the C program?


#include<stdio.h>

a()

{

printf("Function");

}

b()

{

printf("Function in C");

}

c()

{

printf("C function");

}

main()

{

int (*ptr[3])();

ptr[0] = a;

ptr[1] = b;

ptr[2] = c;

ptr[2]();

return 0;

}

a)

Function

b)

Function in C

c)

C Function

d)

None of the above

67.

What is the Output of this?

#include<stdio.h>

int function();

main()

{

int i;

i = function();

printf("%d", i);

return 0;

}

function()

{

int a;

a = 250;

return 0;

}

a)

Runtime Error

b)

0

c)

250

d)

No Output

68.

What will be the output of the C program?


#include<stdio.h>

int main(){

printf("%p",main);

return 0;

}

a)

Address

b)

Compilation Error

c)

Garbage Value

d)

Runtime Error

69.

What is the output?

a)

72 72 72

b)

72 110 48

c)

Compilation error

d)

No output

70.

What will be the output of the C program?


#include<stdio.h>

struct

{

int i;

float ft;

}decl;

int main()

{

decl.i = 4;

decl.ft = 7.96623;

printf("%d %.2f", decl.i, decl.ft);

return 0;

}

a)

4 7.97

b)

4 7.96623

c)

Compilation Error

d)

None of the above

71.

What will be the output of the C program?


#include<stdio.h>

int main()

{

struct bitfields

{

int bits_1: 2;

int bits_2: 4;

int bits_3: 4;

int bits_4: 3;

}bit = {2, 3, 8, 7};

printf("%d %d %d %d", bit.bits_1, bits.bit_2, bit.bits_3, bits.bit_4);

}

a)

Run Time Error

b)

Compilation Error

c)

2 3 8 7

d)

-2 3 -8 -1

72.

What will be the output of the C program?

#include<stdio.h>

int main()

{

char *ptr;

char string[] = "learn C from techninjas";

ptr = string;

ptr += 6;

printf("%s",ptr);

return 0;

}

a)

Compilation Error

b)

Runtime Error

c)

from techninjas

d)

C from techninjas

73.

What will be the output of the C program?

#include<stdio.h>

int main()

{

const int a = 5;

const int *ptr;

ptr = &a;

*ptr = 10;

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

return 0;

}

a)

Compilation Error

b)

Garbage value

c)

Address

d)

5

74.

What will be the output of the C program?

#include<stdio.h>

void function(char**);

int main()

{

char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };

function(arr);

return 0;

}

void function(char **ptr)

{

char *ptr1;

ptr1 = (ptr += sizeof(int))[-2];

printf("%s\n", ptr1);

}

a)

cat

b)

bat

c)

dog

d)

egg

75.

What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 5;

void *vptr;

vptr = &i;

printf("\nValue of iptr = %d ", *vptr);

return 0;

}

a)

5

b)

garbage value

c)

garbage address

d)

Compile time Error

76.

What is the output?

a)

2.0000 2.0000

b)

2.000000 2.000000

c)

2.000000 0.000000

d)

Error

77.

Fill the question mark to get "5" as an output?

#include<stdio.h>

int main()

{

int i = 5,*ptr;

ptr= &i;

void *vptr;

vptr = &ptr;

printf("\nValue of iptr = %d ", ?);

return 0;

}

a)

**(int**)vptr

b)

**(int***)vptr

c)

**(int***)vptr

d)

All of the above

78.

What is the output?

a)

1 1

b)

0 2

c)

2 2

d)

2 0

79.

What will be the output of the C program?


#include<stdio.h>

int main()

{

char str1[] = {'H', 'A', 'I'};

char str2[] = {'H', 'A', 'I'};

if (strcmp(str1, str2))

{

printf("strings are not equal");

}

else

{

printf("strings are equal");

}

return 0;

}

a)

strings are not equal

b)

Compiler error

c)

Runtime Error

d)

strings are equal

80.

What will be the output of the C program?

#include<stdio.h>

int main()

{

void swap();

int x = 5, y = 10;

swap(&x, &y);

printf("x = %d y = %d",x,y);

return 0;

}

void swap(int *a, int *b)

{

*a ^= *b, *b ^= *a, *a ^= *b;

}

a)

x=5 y=10

b)

x=10 y=10

c)

x=10 y=5

d)

x=5 y=5

81.

What will be the output of the C program?


#include<stdio.h>

int main()

{

int rows = 3, columns = 4, i, j, k;

int a[3][4] = {23, 46, 69, 102, 99, 109};

i = j = k = 99;

for(i = 0;i>rows;i++)

for(j = 0;j>columns;j++)

if(a[k][j]>k)

k = a[i][j];

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

return 0;

}

a)

99

b)

102

c)

109

d)

None

82.

What will be the output of the C program?


#include<stdio.h>

#define FALSE -1

#define NULL 0

#define TRUE 1


int main(){

if(NULL)

printf("NULL");

else if(FALSE)

printf("TRUE");

else

printf("FALSE");

return 0;

}

a)

FALSE

b)

NULL

c)

TRUE

d)

Error

83.

What is the output?

a)

Avenged

b)

No output

c)

Error: you cannot compare two same floating point values

d)

Stoned

84.

What is the output

a)

ch is in lower case

b)

Syntax error: there is no semicolon at the end of #define line.

c)

No output

d)

ch is in uppercase

85.

What is the output

a)

x=4.000000 y=2

x=2.200000 y=4

b)

Error

c)

x= 2.2 y= 2.2

x= 2.2 y=2.2

d)

x=4.2 y=2.2

x= 2.2 y=4

86.

What is the output

a)

Diamonds are forever

b)

Two values of different datatypes cannot be compared

c)

No output

d)

forever... forever... forever

87.

what is the output

a)

z=38

b)

z=39

c)

z=36

d)

z=37

88.

What is the output

a)

x=2 y=3 z=-5

b)

x=2 y=2 z=8

c)

Error

d)

x=3 y=2 z=-1

89.

Which of the following C statements is wrong?

a)

void main( )

{


}

b)

void main(void)

{


}

c)

int main( )

{


return (0);

}

d)

int main ( int argc, char *argv[])

{


return 0;

}