• C Programming Video Tutorials

C Programming - Online Quiz



Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers
cprogramming_questions_answers.htm

Q 1 - int x=~1; What is the value of 'x'?

A - 1

B - -1

C - 2

D - -2

Answer : D

Explanation

-2, the one’s compliment of 1 is 1110 (binary) which is equivalent to two’s compliment of 2, ie -2.

Q 2 - The type name/reserved word ‘short’ is ___

A - short long

B - short char

C - short float

D - short int

Answer : D

Explanation

short is used as an alternative of short int.

Answer : B

Explanation

(b). Compilation is the process of translating high level language statements into equivalent machine code, which is object code.

Q 4 - Does both the loops in the following programs prints the correct string length?

#include<stdio.h>

main()
{
   int i;
   char s[] = "hello";

   for(i=0; s[i]; ++i);
      printf("%d ", i);

   i=0; 
   while(s[i++]);
      printf("%d ", i);
}

A - Yes, both the loops prints the correct length

B - Only for loop prints the correct length

C - Only while loop prints the correct length

D - Compile error in the program.

Answer : B

Explanation

In while loop ‘i’ gets incremented after checking for ‘\0’, hence giving 1 more than the length.

Q 5 - Which of the following functions disconnects the stream from the file pointer.

A - fremove()

B - fclose()

C - remove()

D - file pointer to be set to NULL

Answer : B

Explanation

fclose(), it flushes the buffers associated with the stream and disconnects the stream with the file.

Q 6 - Turbo C in 16 bit DOS OS, the correct range of “long double” is,

A - 3.4E-4932 to 3.4E+4932

B - 3.4E-4932 to 1.1E+4932

C - 4.1E-4932 to 5.1E+4932

D - 0.7E-4932 to 1.8E+4932

Answer : B

Explanation

Explanation: The integral and precession value varies depending upon the number of bytes designated for a particular data type.

Q 7 - Which library function can convert an integer/long to a string?

A - ltoa()

B - ultoa()

C - sprintf()

D - None of the above

Answer : A

Explanation

In C, ltoa() function converts long/integer data type to string data type.

char *ltoa(long N, char *str, int base);

Answer : A

Explanation

randomize() picks the current time value as the SEED number to generate random numbers.

Q 9 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A - * / % = + -

B - / * % - + =

C - - + = * % /

D - * / % + - =

Answer : D

Explanation

* / % holds highest priority than + - . All with left to right associativity.

Q 10 - According to ANSI specification, how to declare main () function with command-line arguments?

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

B - int char main(int argc, *argv)

C -

int main()
{
   Int char (*argv argc);
)

D - None of the above

Answer : A

Explanation

Some time, it becomes necessary to deliver command line values to the C programming to execute the particular code when the code of the program is controlled from outside. Those command line values are called command line arguments. The command line arguments are handled by the main() function.

Declaration of main () with command-line argument is,

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

Where, argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program.

Advertisements