Skip to main content

c programming MCQ questions and answers

c programming MCQ  questions and answers

1. Which among the following is the most complete definition of Programming?
           a) Programming is a process to solve any logical problems.
           b) Programming is a process to solve any numerical problem.
           c) Programming is a process to solve any real life problems.
           d) Programming is the process of taking an algorithm and encoding it into a notation (using a                    programming language), so that it can be executed by a computer.
Solution: (d) Programming is the process of taking an algorithm and encoding it into a notation, a programming language, so that it can be executed by a computer

2. Which of the following controls the way in which the computer system works and give means by which users can interact with the computer?
           a) The motherboard
           b) The operating system
           c) The application software
           d) The RAM
Solution: (b) The operating system

3. CPU consists of
          a) ALU, Control Unit
          b) ALU, Main memory, Control Unit
          c) ALU, monitor, Registers
          d) ALU, Control Unit, Hard Disk
Solutions: (a) ALU, Control Unit

4. C was developed by
          a) Alan Turing
          b) Charles Babbage
          c) Ada Lovelace 
          d) Dennis Ritchie
 Solution: (d) Dennis Ritchie

5. C is-
         a) General-purpose programming language
         b) Domain-specific programming language
         c) Page description programming language
         d) None of the above
Solution: (a) C is a General-purpose programming language

6. The relation between bit and byte in digital logic is
         a) 1 byte = 10 bits
         b) 1 byte = 16 bits
         c) 1 byte = 8 bits
         d) 1 byte = 2 bits
Solution: (c) 1 byte is equal to 8 bits

7.Which of the following is not a programming language?
         a) C
         b) Unix
         c) Java
         d) Python
Solution: (b) Unix is an operating system, not a programming language.

8.the binary AND operation of the number"100101" and "110011" result(in decimal)
         a)100001
         b)2
         c)33
        d)63
solution: (c) AND operation between two "1" is one otherwise zero. Hence,the result is binary "100001" which is 33 in decimal.

9.which of the following is not an input device of computer?
         a)Printer
         b)Mouse
         c)Keyboard
        d)Joystick
Solution: Printer is an output device. All other are input device.

10.The process through which an user can find error(s) in a program is called
        a)Processing
        b)Compiling
        c)searching
        d)Debugging
Solution: (d) Debugging is the process of finding error in a computer

11. Algorithm is-
           a) A process or set of rules to be followed in calculations or other problem-solving operations,                  especially by a human.
           b) A process or set of rules to be followed to solve numerical problems only.
           c) A process or set of rules to be followed in calculations or other problem-solving operations,                   especially by a computer.
           d) A process or set of rules to be followed in to solve logical problems only.
Solution: (c) A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer

12. The lowest form of Computer language is
            a) C
            b) BASIC
            c) FORTRAN
            d) Machine language
Solution: (d) Machine language.

13. The software tool that helps a user to interact with computer for a specific purpose are called
            a) Operating system
            b) Application software
            c) Hardware
            d) None
Solution: (b) Application software

14. A half of byte is called
            a) bit
            b) baud
            c) nibble
            d) none of the above
Solution: (c) nibble

15. ‘C’ in CPU denotes-
            a) Common
            b) Computing
            c) Central
            d) Circuitry
Solution: (c) Central

16. The smallest unit that is used for memory storage is-
            a) byte
            b) bit
            c) nibble
            d) baud
Solution: (b) bit

17. CPU uses the _____________ to get the address of the next instructions
             a) Register
             b)instruction register
             c) Program Counter
             d) RAM
Solution: (c) Program Counter

18. Which one of the following statement is the most appropriate?
             a) Pseudo code is basically a diagrammatic representation of the algorithm. Whereas in                           flowchart normal English language is translated into the programming languages to be                         worked on.
             b) Flowchart is diagrammatic representation of the algorithm. Pseudo code is just another                          name of algorithm.
             c) Pseudo code is another name of programming. Whereas in flowchart is diagrammatic                             representation of algorithm.
             d) Flowchart is basically a diagrammatic representation of the algorithm. Whereas in pseudo                   code normal English language is translated into the programming languages to be worked                   on.
Solution: (d) Flowchart is basically a diagrammatic representation of the algorithm. Whereas in pseudo code normal English language is translated into the programming languages to be worked on.

19. What will be the output of the flowchart given below?

                                                 
                a) 20
                b) 21
                c) 10
                d) 0.33
Solution: (b) Y=X/10+2Y => Y=10/10+2*10 => Y=1+20=21

20. The input N from the user is 9. The output of the following algorithm is

               a) 81
               b)720
               c)40320
               d) 362880
Solution: (d) The flowchart finds the factorial of the number 9. Hence, the right answer is 9!=362880

21. The following algorithm is used to find a number X is even or odd. What will be the content of the empty box? [Note: The modulo operator (%) returns the remainder of the left side divided by the right side. So 5%2 will evaluate to 1. (5 / 2 = 2 remainder: 1).
                                                         

               a) X%10=0?
               b) X/10=0?
               c) X/2=0?
               d) X%2=0?
Solution: (d) To find whether a number is odd or even, the number has to be divided by 2. If it is equals to zero, then the number is even. Thus, X%2=0? Condition is appropriate.

22. X is an integer (X=3521). The print value of Y of the flowchart below is
                                               
                 a) 10
                 b) 33552211
                 c) 1253
                 d) 0
Solution: (c) The algorithm finds the reverse of the number X. Hence, the output is 1253

23. The section of the CPU that selects, interprets and sees to the execution of program instructions
                 a) Memory
                 b) Register Unit
                 c) Control Unit
                 d) ALU
Solution: (c) Control unit of the computer helps in maintaining sequence of steps and execute the program

24. In finding maximum number of 3 different numbers, how many decision box will be drawn in the flow chart
                  a) 3
                  b) 4
                 c) 2
                  d) 1
Solution: (c) Considering maximum of 3 numbers the algorithm is below:
Step 1: Start
Start 2: Input A, B, C
Start 3: Let max = A
Start 4: if B > max then max = B
Start 5: if C > max then max = C
Start 6: Output max is largest
Start 7: Stop
In this above example, two comparisons made with the value of max. It can be presented with two decision boxes in a flowchart.

25. The ________ scans the entire C program and translates it as a whole into machine code.
                a) Interpreter
                b) Compiler
                c) Program counter
                d) Operating system
Solution: (b) Compiler

26. User writes a program to solve a particular problem. It may be called
                a) a System software
                b) an Application software
                c) an Assembly programming
                d) a Machine level software
Solution: (b) User writes a program to solve specific tasks known as Application software

27. Which of the following is not a C variable?
                a) Var123
                b) Var_123
                c) 123Var
                d) X_123_Var
Solution: (c) Variable name must not begin with a digit. So, ‘123Var’ is invalid variable declaration in C.

28. The execution of any C program is
             a) Sequential
            b) Parallel
             c) Multi-threading
             d) None of these
Solution: (a) The execution of C program is sequential.

29. Which of the following is a valid C expression?
             a) Var_name=1,000;
             b) Var name=1000;
             c) Var_name=1000;
             d) #Var_name=1000;
Solution: (c) 1st option: Comma cannot be used in variable value, 2nd option: blank space cannot be used in variable name, 4th option: special character # cannot be used in variable name only _ can be used. So, the right option is Var_name=1000.

30. What is the output of the following C code?
                               #include <stdio.h>
                               int main()
                              {
                               int var = 0101;
                               var=var+5;
                               printf("%d", var);
                               return 0;
                               }
                a) 106
                b) 70
                c) 10
                d) Compiler error
Solution: (b) 0101 is octal representation of 65. Thus 65 +5=70 will be stored in var.

31. A function is
                 a) Block of statements to perform some specific tast                               
                 b) It is a fundamental modular unit to perform some task
                c) It has a name and can be used multiple times
                 d) All of the above
Solution: (d) All are true

32. What will be the output? [N.B:- .2f is used to print upto 2 decimal places of a floating point number]
                      #include <stdio.h>
                        int main()
                       {
                       float a = 9.0;
                       printf ("%.2f", (9/5)*a + 10);
                       return 0;
                       }
Solution: 19.00
Since 9 and 5 are integers, integer arithmetic happens in subexpression (9/5) and we get 1 as its value. To fix the above program, we can use 9.0 instead of 9 or 5.0 instead of 5 so that floating point arithmetic happens.

33. What will happen if the following C code is executed?
                     #include <stdio.h>
                       int main()
                      {
                       int main = 10;
                       printf("%d", main);
                       return 0;
                      }
             a) It will cause a compilation error
             b) It will cause a run-time error
             c) It will run without any error and prints 10
             d) It will experience infinite looping
Solution: (c) It will run without any error and prints 10 as ‘main’ is not a keyword and can be used as a variable

34. What is the output of the following program?
                               #include <stdio.h>
                               #define a 10
                               int main()
                               {
                               int a=5;
                               a=a+1;
                               printf("%d",a);
                               return 0;
                               }
                a) 10
                b) 5
                c) 6
                d) Compilation error
Solution: (d) #define is a pre-processor and 10 is stored in a. Thus a cannot be declared as a variable. Thus, the compiler will return compilation error.

35. Which is the only function all C programs must contain?
                a) main()
                b) system()
                c) printf()
                d) scanf()
Solution: (a) main().

36. We use the concept of function for the following reason
                a) To use divide and conquer strategy
                b) For code reusability
                c) Enhances the logical clarity of the program
                d) All of the above.
Solution: (d) All of the above.

37. Which of the following statement is correct?
        I. Keywords are those words whose meaning is already defined by Compiler.
        II. Keywords cannot be used as variable name.
        III. There are 32 keywords in C
        IV. C keywords are also called as reserved words.
                 a) I and II
                 b) II and III
                 c) I, II and IV
                 d) All of the above
Solution: (d) All of the above are correct.

38. What will be the output of the program given below?
                          #include <stdio.h>
                          int main()
                          {
                          a=7;
                          printf("%d", a);
                          return 0;
                          }
               a) 7
               b) 0
               c) 111
               d) Compilation Error
Solution: (d) Variable a is not declared in the scope. Hence compilation error.

39. What is operating system?
               a) collection of programs to manage hardware resources
               b) system service provider to the application programs
               c) link to interface the hardware and application programs 
               d) all of the above
Solution: (d) all of the above

40. The output of the program is
                           #include<stdio.h>
                            int main()
                            {
                             int x=5; y=10; z=20;
                             z=x+y;
                             printf("%d",z);
                             return 0;
                             }
                 a) 15
                 b) 20
                 c) 0
                 d) Compilation error
Solution: (d) While initializing the variables, “;” indicates the end of the line. Thus after initializing the variable x, the line ends. y and z will be undeclared data type. So, the error will be “y and z are not declared in the scope”.

41. Which of the following statement is correct?
                a) Operator precedence determines which operator is performed first in an expression with                       more than one operator with different precedence. Associativity is used when two                                 operators of same precedence appear in an expression
                b) Operator associativity determines which operator is performed first in an expression                             with  more than one operator with different associativity. Precedence is used when two                          operators of same precedence appear in an expression
                 c) Operator precedence and associativity are same.
                 d) None of the above
Solution: (a) Operator precedence determines which operator is performed first in an expression with more than one operator with different precedence, whereas associativity is used when two operators of same precedence appear in an expression

42. Which of the following is correct?
                  a) All operators with same associativity have same precedence
                  b) All operators with same precedence have same associativity
                  c) Associativity and precedence are same thing but named differently in different                                      programming languages
                  d) None.
Solution: (b) All operators with same precedence have same associativity-- This is necessary, otherwise there won’t be any way for compiler to decide evaluation order of expressions which have two operators of same precedence and different associativity.

43. The precedence of arithmetic operators is (from highest to lowest)
                 a) %, *, /, +, –
                 b) %, +, /, *, –
                 c) +, -, %, *, /
                 d) %, +, -, *, /
Solution: (a) The precedence order follows the first option (a)

44. What is the output of the following program?

                                                   #include<stdio.h>
                                                   int main()
                                                   {
                                                   int x=7, y=5, z;
                                                   float w;
                                                   z=x%y;
                                                   w=x/y;
                                                    printf("Value of z and w are %d and %f respectively",z,w);
                                                    return 0;
                                                    }

                  a) Value of z and w are 2 and 1 respectively
                  b) Value of z and w are 2 and 1.400000 respectively
                  c) Value of z and w are 2.000000 and 1.000000 respectively
                  d) Value of z and w are 2 and 1.000000 respectively
Solution: (d) Modulo (%) gives the reminder and division (/) gives the quotient of a division operation. As 7/5 is an integer division, so the output will be 1. Here, w is a floating variable, so it will store the value of 1.000000. Thus z and w would be 2 and 1.000000 respectively.

45. What kind of operator is >= ?
                 a) Arithmetic
                 b) Logical
                 c) Relational
                 d) Bitwise
Solution: (c) Relational operator.

46. What will be the output?

                                           #include <stdio.h>
                                           int main ()
                                           {
                                            int a = 4, b = 15, c = 29;
                                            if (c > b > a)
                                            printf("TRUE");
                                            else
                                            printf("FALSE");
                                            return 0;
                                            }

                  a) TRUE
                  b) FALSE
                  c) Syntax Error
                  d) Compilation Error
Solution: (b) FALSE: (c > b > a) is treated as ((c > b) > a), associativity of '>'
is left to right. Therefore, the value becomes ((29 > 15) > 4) which becomes (1 > 4) thus FALSE.

47. What will be the output?


                                       #include<stdio.h>
                                       int main()
                                       {
                                       int x;
                                       x= 4<5+3 && 7;
                                       printf("%d", x);
                                       return 0;
                                       }

                  a) 0
                  b) 1
                  c) 7
                  d) Compilation error
Solution: (b) 1
This expression is equivalent to:
((4< (5 + 3)) && 7)
i.e., (5 + 3) executes first resulting into 8
then, first part of the expression (4 < 8) executes resulting into 1 (TRUE)
Then, (1 && 7) executes resulting into 1 (TRUE)

48. What will be output?


                                      #include<stdio.h>
                                      int main()
                                      {
                                      int i = 12;
                                      if (i == 10)
                                      printf("i is 10");
                                      else if (i == 15)
                                      printf("i is 15");
                                      else if (i == 20)
                                      printf("i is 20");
                                      else
                                      printf("i is not present");
                                      return 0;
                                      }

                  a) i is 10
                  b) i is 15
                  c) i is 20
                  d) i is not present
Solution: (d) i is not present
None of the conditionals are true hence final else is executed

49. What will be the output?


                                     #include <stdio.h>
                                     int main()
                                     {
                                     int x=2;
                                     if(x=1)
                                     printf("TRUE");
                                     else
                                     printf("FALSE");
                                     return 0;
                                     }

                 a) TRUE
                 b) FALSE
                 c) Compilation Error
                 d) Compiler Dependent
Solution: (a) TRUE
TRUE if(x=1)... "=" is an assignment operator, so 1 will be assigned to x and condition will be true due to if(1).

50. What will be the output?

                                   #include <stdio.h>
                                   int main()
                                   {
                                    if((-10 && 10) && (4>3))
                                    printf("Condition is true.");
                                    else
                                    printf("Condition is false.");
                                    return 0;
                                    }

                     a) Condition is true
                     b) Condition is false
                     c) Error
                     d) No output possible
Solution: (a) Condition is true
Any non-zero value is treated as true for condition. Consider the expressions: if( (-10 && 10) && (3>4) ) =if( (1) && (1) ) =if(1)

51. What will be the output of the following C code? [Assume it’s a 32-bit system]

                         #include <stdio.h>
                         int main()
                         {
                         int x= 70;
                         printf("%c", x);
                         return 0;
                         }

                  a) 70
                  b) F
                  c) 70.0
                  d) Compilation error
Solution: (b) Assume it is a 32-bit machine. So, the compiler allocates 2 bytes for the integer x in its memory. So it will be 0 0 0 0 0 0 0 0 | 0 1 0 0 0 1 1 0 The size of a character is of 1 byte in C, so it will take only the first byte from the right hand side i.e. 0 1 0 0 0 1 1 0 and print the corresponding ASCII value i.e. F.

52. What will be the output?

                              #include <stdio.h>
                              int main()
                              {
                              int x= 7, y= 10;
                              if (!(!x) && y)
                              printf("%d", x);
                              else
                              printf("%d", y);
                              return 0;
                              }

                   a) 7
                   b) 10
                   c) 1
                   d) 0
Solution: (a)
!(!x) = x i.e. x and y both are non-Zero value and equal to 1 (True). Therefore, the statement is True.

53. What is the output of the following C code?

                         #include <stdio.h>
                         int main()
                         {
                         int x=9, y=5, z=3;
                         printf("%d\n", x-x/y*y%z);
                         return 0;
                        }

                 a) 5.4
                 b) 16
                 c) 7
                 d) 1
Solution: (c)
x-x/y*y%z here the operators /, * and % have the same precedence. So they will be calculated from left to right.
Therefore, x – x/y*y%z = 9 – 9 / 5 * 5 % 3 = 9 – 1 * 5 % 3 (integer part of 9/5 = 1) = 9 – 5 % 3 = 9 – 2 = 7

54. What will be the output?


                               #include <stdio.h>
                               int main()
                               {
                               int x;
                               x=(7+6)%5/2;
                               printf("%d\n", x);
                               return 0;
                               }

                 a) 0
                 b) 1
                 c) 0.5
                 d) Compilation error
Solution: (b)
x = (7+6)%5/2 = 13%5/2 (As ( operator have higher precedence) = 3/2 (As % and / has same precedence and will be operator from left to right) = 1 (as only x is an integer)

55. Which of the following operator has the highest precedence?
               a) !
               b) %
               c) +
               d) >
Solution: (a) ! (NOT) has the highest precedence

56. In C program ‘&’ is used in ‘scanf’ to indicate
                 a) AND operation
                 b) Memory location
                 c) Value of the variable
                 d) Value at the memory location.
Solution: (b) ‘&’ is used to indicate the memory location where the value of the variable will be stored after taking input from standard input device.

57. What is the output of the following C code?


                               #include <stdio.h>
                               int main()
                               {
                               int x = 1;
                               if (x == 0)
                               if (x >= 0)
                               printf("true\n");
                               else
                               printf("false\n");
                               return 0;
                               }

                  a) true
                  b) false
                  c) Depends on computer
                  d) Nothing is printed
Solution: (d) x is initialized with 1 and the “if” statement compares it with 0, thus the “if condition” is “false” and the nested “if” statements do not get executed. Hence, the program do not prints anything.

57. Compute the printed value of i for the C program given below

                           #include<stdio.h>
                           int main()
                           {
                           int i=1;
                           i = ++i + i; 
                           printf("%d",i);
                           return 0;
                           }

Solution: 4 is printed. Since ++ is pre-increment operator. It increments the operator by one and then assignment is done. Thus the incremented value of i which becomes 2 and added to it and the result is 4.

58. The control/conditional statements used in C is/are

                  a) if-else statements
                  b) switch statements
                   c) Both (a) and (b)
                   d) None of these
Solution: (c) Both if-else and switch statements are conditional statements in C.

59. What is the output of the following C code?

                                        #include <stdio.h>
                                        int main()
                                        {
                                        int a = 1;
                                        if (a--)
                                        printf("True\n");
                                        if (++a)
                                        printf("False\n");
                                        return 0;
                                        }
                  a) ‘True’ will be printed
                  b) ‘False’ will be printed
                  c) Both ‘True’ and ‘False’ will be printed
                  d) Nothing will be printed
Solution: (c) ‘a--’ post-increment the value of a. Thus, the if statement is executed as the value of a is considered as 1 which is true. ‘++a’ pre-increment the value of a. Thus, the decremented value of a (which is 0) is incremented first and then assigned. So, both the if statements are executed ad correspondingly both True and False will be printed.

60. Switch statement accepts
                a) int
                b) char
                c) long
                d) All of the above
Solution: (d) Integer, character and long constants are accepted in switch statements.

71. What is the output of the following program?

                            #include <stdio.h>
                            int main()
                            {
                            int k = 1;
                            for (k)
                            printf("Hello");
                            return 0;
                            }

                  a) ‘Hello’ will be printed once
                  b) No output
                  c) Varies depending on computer
                  d) Compilation error
Solution: (d) The correct syntax of for loop is not written, thus the compiler will return error.

72. The loop which is executed at least once is
                  a) while
                  b) do-while
                  c) for
                  d) none of the above
Solution: (b) do-while loop is executed at least once even though the condition is false.

73. If multiple conditions are used in a single if statement then the testing of those conditions are done
                 a) From Right to Left
                 b) From Left to right
                 c) Randomly
                 d) None
Solution: (b) Multiple conditions are tested from Left to right

74. What will be the value of a, b, c after the execution of the followings
       int a=10,b=7,c=125;
       c /= ++a * --b;
                 a) a=11, b=7,c=0;
                 b) a=10, b=6,c=1;
                 c) a=11, b=6,c=1;
                 d) a=10, b=7,c=0;
Solution: (c) ++a * --b is computed as (a=a+1)*(b=b-1)  (11)*(6)=66
c/=66  c=c/66  c=125/66=1 (as c is integer)
Hence the right answer is a=11, b=6 and c=1

75. Which statement is correct for the following lines?

       switch(month)
       {
        case < 30:
        printf(“It’s February”);
       default:
       printf(“It’s not February”);
       }

                  a) It’s perfectly fine
                  b) It will print both statements
                  c) It will give a compilation error
                  d) More information required
Solution: (c) Compilation error. Because only equality can be checked in case. Not <,>,<=,>= etc.

76. How many times “Hello” will be printed when the following code is executed?

                                          #include<stdio.h>
                                          int main()
                                          {
                                         int i=6;
                                         while(--i>0)
                                         printf("Hello\t");
                                         returne()
                                         }

Solution: 5
We have declared and initialize the variable i = 6, the condition is (--i > 0). Here i is pre-decremented once by one until it becomes 1. It will be 5, 4, 3, 2 and 1 for each iteration.

77. What will be the output of the following program?

                                                          #include <stdio.h>
                                                          int main()
                                                          {
                                                          int x = 1;
                                                          switch (x)
                                                          {
                                                         case 1: printf("Choice is 1 \n");
                                                         default: printf("Choice other than 1 \n");
                                                          }
                                                          return 0;
                                                          }

                  a) Choice is 1
                  b) Choice other than 1
                  c) Both (a) and (b)
                  d) Syntax error
Solution: (c)
Since “break;” statement is not used after print statement, it will execute the default instruction as well.

78. What will be the output?


                                         #include <stdio.h>
                                         int main () {
                                         int a = 10;
                                         do {
                                         printf("%d ", a);
                                         a++;
                                         }while( a >= 20 );
                                         printf("%d ", a);
                                         return 0;
                                         }
                  a) 10 10
                  b) 10 11 12 … 20 20
                  c) 10 11 12 … 20 21
                  d) 10 11
Solution: (d)
The loop body is executed once due to false conditional checking. Hence, 10 is printed within the loop. While exiting the loop the value of a is incremented to 11. So, after the loop 11 will be printed.

79. What will be printed when the following code is executed?


                                             #include <stdio.h>
                                             int main ()
                                             {
                                             int i
                                             for(i=0;i<5;++i);
                                             printf("%d ",i);
                                             return 0;
                                             }

                 a) 0 1 2 3 4 5
                 b) 0 1 2 3 4
                 c) 5
                 d) 0
Solution: (c)
“printf” is a separate instruction as it is not included within the loop. There is a semicolon “;” after the for loop. After the execution of loop printf statement prints the value of i (as updated in the loop) i.e. 5.

Comments

Popular posts from this blog

array mcq questions in c

1. The elements of an array can be accessed by its            a) name            b) index            c) dimension            d) none of the above Solution: (b) An array is accessed by its index. 2. The elements of array are stored in contiguous memory due to             a) This way computer can keep track only the address of the first element and the addresses                     of  other elements can be calculated.             b) The architecture of computer does not allow arrays to store other than serially             c) Both             d) None Solution: (a) This way computer can keep track only the address of the first element and the addresses of other elements can be calc...

Introduction to c language

Introduction to c C is a programming language that lets us give a computer very specific commands. C was invented in 1972. It's one of the oldest languages to be used even today! It is one of the most widely used programming languages in the world. It has influenced many popular languages, especially c++. But why do we still use such an old programming language? why not something newer and easier to understand,like python? Let's find out. History of C Language History of C language  is interesting to know. Here we are going to discuss a brief history of the c language. C programming language  was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. Dennis Ritchie   is known as the   founder of the c language . It was developed to overcome the problems of previous languages such as B, BCPL, etc. Initially, C language was developed to be used in  UNIX operating sys...