Skip to content

117+ MCQS of Programming with C With Answers | NTS

  • by
computer science mcqs
Spread the love

In Help.com.Pk you will get all type of computer Science MCQS with answer so you pratice and perform any type of Gov test like NTS or University and get good results as output. Below MCQS used for NTS and other type of government online test system. all computer science mcqs and answers are uploaded on Help.com.Pk

1.Choose the correct Statement

a)      Use of goto enhance the logical clarity of Code.

b)      Use of goto Makes the debugging task easier

c)       Use of goto when you want to jump out of a nested loop.

d)      Never use goto

2.Which is true of Conditional Completion?

a)      It is take care of by compiler

b)      It is setting the compiler option conditionally

c)       It is a compiling a program based on a condition

d)      It is taken care of by the per-processor

3.C was primarily develop as a

a)      System programming language

b)      General purpose language

c)       Data processing language

d)      None of the above

4.C is a

a)      High level language

b)      Low level language

c)       High level language with some low level features

d)      Low level language with some high level features

5.Even if a particular implementation doesn’t limit the number of character is an identifier, it is advisable to be concise because

a)      Chances of typographic errors are less

b)      It may be processed by assembler, loaders etc. Which may have their own rules that may contradict the language rules

c)       By being concise, one can be mnemonic

d)      None of the above

6.The minimum number of temporary variables needed to swap the contents of the variables is

a)      1   b) 2    c)  3 (d)  0

7.The purpose of the following program fragment

             b = s + b;

             s =  b – s;

             b = b – s;

8.where s,b are two integers is to

a)      Transfer the content of s to b

b)      Transfer the content of b to s

c)       Exchange (swap) the contents of s and b

d)      Negate the content of s and b

9.Consider the function

             Find(int x, int y)

             (return ( x<y) ? 0 : ( x  – y )) 😉

10.Let a,b be two non-negative integers. The call find (a, b) can be used to find the

a)      Maximum of a,b

b)      Positive difference a, b

c)       Sum of a, b

d)      Minimum of a, b

11.Let a,b be two non-negative. The call find(a, find(a,b) can be used to find the positive difference of a and b?

a)      Find(a,b) + find(b,a)

b)      Find(a,find(a,b))

c)       a+ find(a,b)

d)      b+find(a,b)

12.if integer needs two bytes of storage, then maximum value of an unsigned integer is

a)      216-1  b) 215 -1            c) 216     d) 215

13.if integer needs two bytes of storage, then maximum value of an signed integer is

a)      216-1  b) 215 -1            c) 216     d) 215

14.printf( “ %d” , printf(“tim”));

a)      Result is a syntax error

b)      Output tim3

c)       Output garbage

d)      Print tim and terminates abruptly

 

15.if abc is the input, then the following program fragment

             char x, y, z;

             printf( “d”, scanf ( “%c%c%c , &x, &y, &z)); result in

a)      A syntax error

b)      Fatal error

c)       Segmentation violation

d)      Printing if 3

16.Consider the statements

             putchar (getchar());

             putchar (getchar());

             if

             a

             b

             is the input the output will be

a)      an error message

b)      this cannot be the input

c)       ab

d)      a b

17.Let a,b be two positive integers which of the following options correctly relates /  and %?

a)      b = (a/b)*b + a%b

b)      a = (a/b)*b + a%b

c)       b = (a/b)*b + a%b

d)      a = (a/b)*b + a/b

18.Literal means

a)      a string

b)      a string constant

c)       a character

d)      an alphabet

19.Length of the string “correct” is

a)      7

b)      8

c)       6

d)      Implementation dependent.

 

20.which of the following are the true regardless of the implementation?

a)      Sizeof(int) is not less than sizeof(long)

b)      Sizeof(Short) is not less than sizeof(lint)

c)       Sizeof(double) is equal sizeof(unsigned)

d)      Sizeof(double) is not less than sizeof(float)

21.Coercion

a)      Take place across an assignment operator.

b)      Take place if an operator has operands of different data types.

c)       Means string

d)      None of above

22.choose the correct statements.

a)      Casting refers to implicit type conversion

b)      Coercion refers to implicit type conversion

c)       Casting refers to explicit type conversion

d)      Coercion refer to explicit type conversion.

23.Consider the following program fragment

             char c = ‘a’ ;

             while (c++ <== ‘z’)

             putchar (xxx);

   if the required output is abcedfghijklmnopqrstwxyz, then xxx should be

a) c                     b) c++               c) c-1                 d) –c

24.Which of the following comments are true?

a)      C provides no input-ouput features

b)      C provides  no file access features.

c)       C borrowed most of its idea from BCPL.

d)      C provides no features to manipulate composite objects.

25.if y integer type then the expressions.

             3+ (y-8) / 9 and (y-8) / 9 + 3

a)      Must yield the same value

b)      Must yield different values

c)       May or may not yield the same value

d)      None of the above

 

 

26.if y is the type then the expressions

             3+ (y-8) / 9 and (y-8) / 9 + 3

Yield the same value if

a)      Y is an even number

b)      Y is an odd number

c)       Y – B is an integral multiple of 9

d)      Y – 8 is an integral multiple of 3

27.Integer division result

a)      Truncation

b)      Rounding

c)       Overflow

d)      None of above

28.Which of the following comment about EOF are true?

a)      Its value is defined within stdio.h

b)      Its value is implementation depent.

c)       Its value can be negative.

d)      Its value should not equal the integer equivalent of any character

29.The value of an automatic variable that is declared but not initialized will be

a) 0                     b)  -1                 c) unpredictable           d) None

30.Choose the correct statement.

a)      An identifier may start with an underscore

b)      An identifier may end with an underscore

c)       IF us a valid identifier

d)      The number of significant character is an identifier is implementation dependent.

31.Choose the correct statement.

a)      Constant expressions are evaluated at compile time.

b)      String constant can be concatenated at compile time.

c)       Size of array must be known at compile time.

d)      None of above

32)  the const feature can be applied ti

a) an identifier              b) an array

c) an array argument  d) none of the above

33.Which of the following operators takes only integer operands?

a) +                    b) *                    c) /                     d) %

34.In an expression involving if operator evaluation

a)      Will be stopped if one of its components evaluates to false

b)      Will be Stopped if one its Components evaluates to true

c)       Take place from right to left

d)      Take place from left to right

33.

34.Pick the Operator that associate from the left

a) +                    b)  ,                 c) =                     d) <

35.Pick the Operator that associate from the right

a) ?;                   b)  +=               c) =                     d) !=

36.The operator . ,  || , < , = , if arranged in the ascending order of the precedence reads

a)      . , || ,  < , = ,

b)      = , < ,  || , .

c)       = , || ,  < , .

d)       < , || , =  , .

37.Pick the operators whose meaning is context dependent.

a)      *                   b)  #

C) &                           d) No such operator exists.

38.Pick the operators that associate from the left.

a) &&                                                b) ||

c) ||                                                   d) ,

39.The following code fragment

             Int      X, Y = 2,  z, a;

             X =   ( y *= 2)  + (z = a = y ) ;

             Printf ( “%d” , x);

a) print 8

b) print 6

c) print 6 or 8 depending on the compiler implementation

d) is syntactically

 

 

40.if n has the value 3, then the output of the statement printf( “ %d %d” , n++, ++n)

a)      Is 3 5                                                                 b) is 4   5

c) Is  4 4                                                                    d) is implementation

 

41.x -= y +1; means

a) x=x-y +1

b) =  -x -y  – 1

C) x  = x + y  + 1

d)  x = x  – y – 1

42.Which of the following comments about the ++ operator are correct?

a) it is unary operator

b) The operand can come before a after the operator.

c) it cannot be applied to an expression.

d) it associates from the right

43.in standard C, trigraphs in the source program are translated

a)      Before the lexical analysis

b)      After the syntax analysis

c)       Before the recognition of escape character in strings

d)      During the intermediate code generation phase

44.The expression 5  – 2 – 3 * 5 – 2   Will evaluate to 18, if

a)      – is left associative and * has precedence over –

b)      – is right associative and * has precedence over – 

(c) It cannot be applied to an expression. (d) It associates from the right.

45.In standard C, trigraphs in the source program are translated

(a) Before the lexical analysis

(b) After the syntax analysis

(c) Before the recognition of escape characters in strings

(d) During the intermediate code generation phase

 

46.The expression 5 – 2 – 3 ” 5 – 2 will evaluate to 18, if

(a) – is left associative and • has precedence over –

(b) – is right associative and • has precedence over –

(c) – is right associative and – has precedence over •

(d) – is left associative and – has precedence over •

47.printf (“%c”, 100);

(a) prints 100

(b) prints the ASCII equivalent of 100

(c) prints garbage (d) none of the above

48.The program fragment

int i. = 263;

putcher (i);

(a) prints 263

(b) prints the ASCII equivalent of 263

(c) rings the bell

(d) prints garbage

47.Which of the following comments regarding the reading of a string, using scan! (with %s option) and gets, is true?

a) Both can be used interchangeably.

(b) scanf is delimited by end of line, while gets is not.

(c) scanf is delimited by blank space. while gets is not.

(d) None of the above.

48.The following statement printf (“%f*, 9/5); prints

(a) 1.8

(b) 1.0

(c) 2.0

(d) None of the above

49.The statement

printf (•%f*, (float19/51); prints

(a) 1.8

(b) 1.0

(c) 2.0

(d) None of the above

50.Which of the following are not keywords in C?

(a) printf

(b) Main

(c) IF

(d) None of the above

51.The following program fragment unsigned i = 1;

int j = -4;

printf(“%u”, I + j ); prints

(a) garbage

 (b) -3

(C) An integer that changes from machine to machine

(d) none of the above

52.If the following program fragment (assume negative numbers are stored in 2’s complement form)

unsigned i = 1;

int j = -4 ;

printf (“%u”, i + j);

prints x. then printf (“%d”, 8 * sizeof (int) ) ;

outputs an integer that is same as (log in the answers are to the base two)

(a) an unpredictable value        (b) 8*log (x+3)

(c) log (x+3) (d) none of the above

53.Choose the statements that are systactkally correct.

 

/* Is /* this a valid */ comment */

for ( ; ; ) ;

return;

return (5+2);

 

54.The following program fragment

for(i = 3; i < 15; i += 3;  ;

printf (“%d” ,  i) ;

results in

(a) a syntax error

(b) an execution error

(c) printing of 12      

(d) printing of 15

55.The following program fragment

For ( i = 1; i <5 ; ++i)

if (i == 3) continue;

else printf(“%d”, i);

results in the printing of

(a) 1 2 4 5    (b) 1 2 4      (c) 2 4 5    (d) none of the above

 

56.The following program fragment

if (a = 0)

Prinf(“a is zero”);

else

printf(“a is not zero”);

results in the printing of

(a) a is zero (b) a is not zero

(c) nothing      (d) garbage

 

70. The following statements
for (i. = 3; i c 15; i 4.= 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
71. If a 9, b = 5 and c=3. then the expression (a – a /b • b%c)
(a) true (b) false (c) invalid      (d) 3 7 11 15\> a%b%c evaluates to
(d) 0
72. In a for loop. if the condition is missing, then.
(a) it is assumed to be present and taken to be false
(b) it is assumed to be present and taken to be true
(c) it results in a syntax error
(d) execution will be terminated abruptly
73. in a for loop, if the condition is missing, then infinite looping can be avoided by a
(a) continue statement (b) goto statement
(c) return statement (d) break statement
74. Choose the correct statement.
(a) 0 represents a false condition.
(b) Non-zero value represents a false condition.
(c) 1 represents a false condition.
(d) Anything that is not 1. represents a false condition.
75. Which of the following comments about for loop are correct?
(a) Index value is retained outside the loop.
(b) Index value can be changed from within the loop.
(c) goto can be used to jump, out of loop.
(d) Body of the loop can be empty.
76. Which of the following comments about for loop are correct?
(a) Using break is equivalent to using a goto that jumps to the statement immediately following the loop.
(b) Continue is used to by-pass the remainder of the current pass of the loop.
(c) If comma operator is used, then the value returned is the value of the right operand.
(d) It can always be replaced by a while loop.
77. Choose the correct answers.
(a) for loops can be nested
(b) Nested for loop can’t use the same index variable
(c) Nested for loop can’t overlap
(d) None of the above
Programming with C
78. Consider the following program fragment
if (a > b)
if (b > c)
s1;
else s2;
s2 will be executed if
(a) a <= b (b) b>c (c ) b <= c and a<= b (d) a > b and b<= c
79. If switch feature is used, then
(a) default case must be present
(b) default case. if used, should be the last case
(c) default case, if used. can be placed anywhere
(d) none of the above
80. The switch feature
(a) can always be replaced by a nested if-then-else clause
(b) enhances logical clarity
(c) can’t always be replaced by a nested i f -then-else clause
(d) none of the above

81. break statement can be simulated by using
(a) goto (b) return
(c) exit
’82. The following program fragment
if (2 < 1)
;
else
x = (2 < 0)? printf (“one’) printf (“four”);
printf(“%d” , x);
(a) prints nothing
(b) result is a syntax error
(c) prints four0
(d) None of above

*83. Consider the following program fragment if (a > b)
printf (“a > b”°) ;
else
printf I ‘else part “);
printf (“a<=b”);

a <= b will be printed if
(a) a > b (b) a < b (c) a = = b ( d) none of the above

 

 

87. The above statement can never print
(a) one (b) two (c) three (d) four
88. The following program fragment
int x= 9, y = X, 1;
for (1 = 11 i < 4; ++i)
x+=x;
outputs an integer that is same as
(a) 8 * Y (b) y • (1 + 2.+3 + 4)
(c) y • 4 (d) Y • y
89. Using goto inside for loop is equivalent to using
(a) continue (b) break (c) return (d) none of the above
90. Choose the correct statements.
(a)All the elements of the array should be of the same data type and storage class.
(b) The number of subscripts determines the dimension of the array.
(c) The array elements need not be of the same storage class.
(d) In an array definition, the subscript can be any expression yielding a non-zero integer value.
91. Consider the declaration
static char hello [ ]= hello” ;
The output of printf (“%s \n”, hello) ;
will be the same as that of
(a) puts ( “hello” ) ; (b) puts (hello) ;
(c) printf(“%s\n”, “hello”); (d) puts ( ‘hello\n” ) ;
· 92. If storage class is missing in the any definition, by default it win be taken to be
(a) automatic
(b) external
(c) static
(d) either automatic or external depending on the place of occurrence.
93. The following program fragment
int x[5][5], i, j;
for(i = 0; i < 5; ++i)
for(j = 0; j < 5; J++)
X[i][j] = x [i] [j];

(a) transposes the given matrix x (b) makes the given matrix x, symmetric
(c) doesn’t alter the matrix x (d) none of the above
94. Which of the following features of C is meant to provide reliable access to special memory locations?
(a) static_const (b) pragma (c) volatile (d) immutable

95. Consider the array definition
int num[10] = (3, 3, 3);
Pick the correct answers.
(a) num[9] is the last element of the array num
(b) The value of num[8] is 3
(c) The value of num [ 3 ] is 3
(d) None of the above.

96. Consider the following type definition.
typedef char x(10];
x myArray [5];
What will be the size of my Array) be? (Assume one character occupies 1 byte)
(a) 15 bytes (b) 10 bytes (c) 50 bytes (d) 30 bytes
97. While passing an array as an actual argument. the function call must have the array name
(a) with empty brackets (b) with its size
(c) alone (d) none of the above
98. The following program
main ( )
static int a[] a (7, 6 ,9);
printf(“%d” , 2 [a] + a[2]
(a) results in bus error (b) results in a segmentation violation error
(c) will not compile successfully (d) none of the above
99. The parameter passing mechanism for an array is
(a) call by value (b) call by value-result
(c) call by reference (d) none of these
110. Consider the statement
int val[2][14] = (1 , 2 ,3 ,4 ,5 ,6 ,7 ,8 );
4 will be the value of
(a) val [1] [4] (b) val [0] [4]

(c) val [1] [1] (d) none of the above

101. The maximum number of dimensions an array can have in C is
(a) 3 (b) 4 (c) 5 (d) compiler dependent

112. The following program fragment
int m, n, b = m = n = 8;
char wer [80] ;
sprintf (wer, %d%de%d, m, n, b) ;
puts (wer);
(a) prints the string 8 8 8 (b) prints the null thing
(c) prints the string 888 (d) none of the above

103. Under which of the following conditions. the size of an one-dimensional array need not be specified?
(a) when initialization is a part of definition
(b) when it is a declaration
(c) when it is a formal parameter
(d) when it is an actual argument
104. If a two dimensional array is used as a formal parameter. then
(a) both the subscripts may be left empty
(b) the first (row) subscript may be left empty
(c) the first subscript must be left empty
(d) both the subscripts must be left empty
· 105. The following program
main()
static char a[3](4] = {“abcd”, “mnop”, “fghi”};
putchar(**a);
(a) will not compile successfully (b) results in run-time error
(c) prints garbage (d) none of the above

· 106. C does no automatic array bound checking. This is
(a) true (b) false
(c) C’s asset (d) C’s shortcoming
Answer the next three questions based on the program fragment given below
int hh = 16;
;static char wer[] = “NC SUBSTITUTE FOR HARD WORK”:

107. printF(“%10.5s”, wer);
outputs
(a) NO SU
(b) NO SUBSTIT
(c) NO SU
(d) UTE F
108. printF(“%-10.5s”, wer);
outputs
(a) NO SU
(b) NO SUBSTIT
(c) NO SU
(d) UTE F

109. printf(“%-10. “S” , hh , wer ; outputs
(a) NO SU (b) NO SUBSTITUTE FO
(c) NO SU (d) error message
110. If n has the value 3, then the statement a ( ++n) = n++;
(a) assigns 3 to a (5) (b) assigns 4 to a [5]
(c) assigns 4 to a [4 ] (d) what is assigned is compiler-dependent
111. Choose the statement that best defines an array.
(a) It is a collection of items that share a common name.
(b) It is a collection of items that share a common name and occupy consecutive memory locations.
(c) It is a collection of items of the same type and storage class that share a common name and occupy consecutive memory locations.
(d) None of the above.
112. Choose the correct statements.
(a) Strictly speaking C supports 1-dimensional arrays only.
(b) An array element may be an array by itself.
(c) Array elements need not occupy contiguous memory locations.
(d) None of the above.
113. The order in which actual arguments are evaluated in a function call
(a) is from the left (b) is from the right
(c) is compiler-dependent (d) none of the above
114. If a global variable is of storage class static, then
(a) the static declaration is unnecessary if the entire source code is in a single file
(b) the variable is recognized only in the file in which it is defined
(c) it results in a syntax error
(d) none of the above
115. Which of the following statements are correct?
(a) It is possible for a function to access a variable that is local to another function.
(b) Two local variables may have the same name.
(c) The scope of a local variable should be a function.
(d) The scope of a local variable may be a single statement.

116. The default parameter passing mechanism is
(a) call by value (b) call by reference
(c) call by value result (d) none of the above
117. Choose the correct statements.
(a) During external variable definition, storage is set aside by the compiler.
(b) During external variable declaration, no storage is set aside by the compiler.
(c) The use of external variables may make debugging difficult.
(d) None of the above.

Leave a Reply

Your email address will not be published.