C Multiple Choice Questions and Answers

C MCQ - Multiple Choice Questions and Answers

Our 1000+ C Multiple Choice Questions and Answers focuses on all areas of C Programming Language covering 100+ topics in C. These topics are chosen from “The C Programming Language” by Kernighan & Ritchie, the most authoritative book on C.

C Questions Highlights

The multiple-choice questions on C are organized chapter-wise and each chapter is further organized topic-wise. Most of these questions have C code snippets and their runtime output, along with a detailed explanation. The C code is compiled and tested on x86-32 and x86-64 bit Linux systems.

advertisement

Who should Practice these C Questions?
– Anyone wishing to sharpen their skills in the C programming language
– Students preparing for mid-term tests and end-semester exams on C language
– Anyone preparing for aptitude tests in C (both objective type test and C coding written test)
– Anyone preparing for C interviews (campus/off-campus interviews, walk-in interview, and company interviews)
– Anyone preparing for entrance exams (GATE, GRE) & other competitive exams on C language

2. Multiple Choice Questions on Control Flow Statements in C

advertisement
advertisement

The section contains C Language multiple choice questions on switch statements, if-then-else statements, for and while loops, break and continue, goto and labels.

  • If-then-else Statements – 1
  • If-then-else Statements – 2
  • Switch Statements – 1
  • Switch Statements – 2
  • For Loops – 1
  • For Loops – 2
  • While Loops – 1
  • While Loops – 2
  • Break and Continue – 1
  • Break and Continue – 2
  • Goto & Labels – 1
  • Goto & Labels – 2
  • 4. Multiple Choice Questions on Pointers and Arrays in C

    advertisement

    The section contains C Programming multiple choice questions and answers on pointers and addresses, function arguments, arrays, address arithmetic, character pointers and functions, multidimensional arrays, pointer arrays initialization, command line arguments and complicated declarations.

  • Pointers and Addresses – 1
  • Pointers and Addresses – 2
  • Pointers and Function Arguments – 1
  • Pointers and Function Arguments – 2
  • Pointers and Arrays – 1
  • Pointers and Arrays – 2
  • Address Arithmetic – 1
  • Address Arithmetic – 2
  • Character Pointers and Functions – 1
  • Character Pointers and Functions – 2
  • Pointers to Pointers – 1
  • Pointers to Pointers – 2
  • Multidimensional Arrays – 1
  • Multidimensional Arrays – 2
  • Initialization of Pointer Arrays – 1
  • Initialization of Pointer Arrays – 2
  • Pointers Vs. Multi-dimensional Arrays – 1
  • Pointers Vs. Multi-dimensional Arrays – 2
  • Command Line Arguments – 1
  • Command Line Arguments – 2
  • Pointers to Functions – 1
  • Pointers to Functions – 2
  • Complicated Declarations – 1
  • Complicated Declarations – 2
  • advertisement

    7. MCQs on Floating Point & Sizeof Operator in C

    The section contains C Language MCQs on float datatype and sizeof keyword.

  • Float Datatype – 1
  • Float Datatype – 2
  • Sizeof Keyword – 1
  • Sizeof Keyword – 2
  • 8. Multiple Choice Questions on Enumerations and Typedefs in C

    The section contains C multiple choice questions and answers on enums and typedef.

  • C Enums – 1
  • C Enums – 2
  • C Typedef
  • 9. C MCQs on String Operations

    advertisement

    The section contains C MCQs on string operations, character and error handling.

  • String Operations – 1
  • String Operations – 2
  • String Operations – 3
  • String Operations – 4
  • Character Handling – 1
  • Character Handling – 2
  • Error Handling
  • 11. C MCQs on Dynamic Memory Allocation

    The section contains C MCQs on static and dynamic memory allocation, dma functions, memory leak and dangling pointers.

  • Static vs Dynamic Memory Allocation
  • DMA Functions, Memory Leak, Dangling Pointers – 1
  • DMA Functions, Memory Leak, Dangling Pointers – 2
  • 12. Multiple Choice Questions on C Preprocessor

    The section contains C multiple choice questions and answers on pragma, stringizers, conditional preprocessor directives and token concatenation.

  • Pragma
  • Stringizers
  • Conditional Preprocessor Directives – 1
  • Conditional Preprocessor Directives – 2
  • Token Concatenation
  • 13. Miscellaneous Topics in C

    The section contains questions on inline, endianness, recursion and signed qualifier.

  • Inline
  • Endianness
  • Recursion
  • Signed Qualifier
  • Sample C Programming Multiple Choice Questions

    1. Comment on the output of following C code:

    1.     #include <stdio.h>
    2.     main()
    3.     {
    4.         char *p = 0;
    5.         *p = 'a';
    6.         printf("value in pointer p is %c\n", *p);
    7.     }

    a) It will print a
    b) It will print 0
    c) Compile time error
    d) Run time error
    View Answer

    Answer:d
    Output:
    $ cc pgm.c
    $ a.out
    Segmentation fault (core dumped)

    2. What is the output of this C code?

    1.    #include <stdio.h>
    2.    main()
    3.    {
    4.        if (sizeof(int) > -1)
    5.            printf("True");
    6.        else
    7.            printf("False");
    8.    }

    a) True
    b) False
    View Answer

    Answer:b
    Output:
    $ cc pgm.c
    $ a.out
    False

    3. What is the output of this C code?

    1.     #include <stdio.h>
    2.     main()
    3.     {
    4.         char *p = "Sanfoundry C-Test";
    5.         p[0] = 'a';
    6.         p[1] = 'b';
    7.         printf("%s", p);
    8.     }

    a) abnfoundry C-Test
    b) Sanfoundry C-Test
    c) Compile time error
    d) Run time error
    View Answer

    Answer:d
    Output:
    $ cc pgm.c
    $ a.out
    Segmentation fault (core dumped)

    4. What is the output of this C code?

    1.     #include <stdio.h>
    2.     int main()
    3.     {
    4.         float f = 0.1;
    5.         if (f == 0.1)
    6.             printf("True");
    7.         else
    8.             printf("False");
    9.     }

    a) True
    b) False
    View Answer

    Answer:a
    Output:
    $ cc pgm.c
    $ a.out
    False

    5. What is the output of this C code?

    1.     #include <stdio.h>
    2.     main()
    3.     {
    4.         int n = 0, m = 0;
    5.         if (n > 0)
    6.             if (m > 0)
    7.                 printf("True");
    8.         else 
    9.             printf("False");
    10.     }

    a) True
    b) False
    c) No Output will be printed
    d) Run Time Error
    View Answer

    Answer:c
    Output:
    $ cc pgm.c
    $ a.out
    $

    Important Links:

    advertisement
    Manish Bhojasia - Founder & CTO at Sanfoundry
    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter