1000 C Questions and Answers

Our C questions and answers focuses on all areas of C programming language covering 63+ topics in C. These topics are chosen from “The C Programming Language” by Kernighan & Ritchie, the most authoritative book on C.

Highlights
- 1000+ Multiple Choice Questions & Answers in C with explanations
- Lots of MCQs with C code/programming snippet and its output
- Every MCQ set focuses on a specific topic in C Language
- C programming code compiled and tested on x86-32 bit Linux systems

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

Here’s list of Questions & Answers on C Programming with 63+ topics:

1. Questions on Data Types, Operators and Expressions in C

Variable Names – 1
Data Types and Sizes – 1
Constants – 1
Declarations – 1
Arithmetic Operators – 1
Relational & Logical Operators – 1
Type Conversions – 1
Increment and Decrement Operators – 1
Bitwise Operators – 1
Assigment Operators & Expressions – 1
Conditional Expressions – 1
Precedence and Order of Evaluation – 1
Precedence and Order of Evaluation – 2
Precedence and Order of Evaluation – 3
Variable Names – 2
Data Types and Sizes – 2
Constants – 2
Declarations – 2
Arithmetic Operators – 2
Relational & Logical Operators – 2
Type Conversions – 2
Increment and Decrement Operators – 2
Bitwise Operators – 2
Assigment Operators & Expressions – 2
Conditional Expressions – 2
Precedence and Order of Evaluation – 4
Precedence and Order of Evaluation – 5
Precedence and Order of Evaluation – 6

2. Questions & Answers on Control Flow Statements in C

If-then-else Statements – 1
Switch Statements – 1
For Loops – 1
While Loops – 1
Break and Continue – 1
Goto & Labels – 1
If-then-else Statements – 2
Switch Statements – 2
For Loops – 2
While Loops – 2
Break and Continue – 2
Goto & Labels – 2

3. Questions on C Functions and Structure of a Program

Basics of Functions – 1
Functions Returning Non-integers – 1
External Variables – 1
Scope of a Variable – 1
Static Variables – 1
Register Variables – 1
Automatic Variables – 1
C-Preprocessor – 1
File Inclusion – 1
Macro Substitution – 1
Conditional Inclusion – 1
Basics of Functions – 2
Functions Returning Non-integers – 2
External Variables – 2
Scope of a Variable – 2
Static Variables – 2
Register Variables – 2
Automatic Variables – 2
C-Preprocessor – 2
File Inclusion – 2
Macro Substitution – 2
Conditional Inclusion – 2

4. Questions & Answers on Pointers and Arrays in C

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

5. Questions on Structures, Unions and Bit-Fields in C

Basics of Structures – 1
Structures and Functions – 1
Arrays of Structures – 1
Pointer to Structures – 1
Self-Referential Structures – 1
Table Lookup – 1
Typedefs – 1
Unions – 1
Bit-fields – 1
Basics of Structures – 2
Structures and Functions – 2
Arrays of Structures – 2
Pointer to Structures – 2
Self-Referential Structures – 2
Table Lookup – 2
Typedefs – 2
Unions – 2
Bit-fields – 2

6. Questions & Answers on Input and Output in C

Standard Input & Output – 1
Formatted Output – 1
Variable Length Argument – 1
Formatted Input – 1
File Access – 1
Error Handling – 1
Line Input & Output – 1
String Operations – 1
Character Class Testing & Conversions – 1
Ungetc – 1
Storage Management – 1
Mathematical Functions – 1
Random Number Generation – 1
Standard Input & Output – 2
Formatted Output – 2
Variable Length Argument – 2
Formatted Input – 2
File Access – 2
Error Handling – 2
Line Input & Output – 2
String Operations – 2
Character Class Testing & Conversions – 2
Ungetc – 2
Storage Management – 2
Mathematical Functions – 2
Random Number Generation – 2

7. Questions on Floating Point & Sizeof Operator in C

Float Datatype – 1
Sizeof – 1
Float Datatype – 2
Sizeof – 2

Sample C Programming Questions & Answers:

1. Comment on the output of following 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
$

If you liked some of these questions and would like to learn lots of deep C secrets, you shall attempt to work on the complete set of C questions and answers mentioned above. It will immensely help anyone trying to crack a code or an interview.

Here’s the list of Best Reference Books in C Programming Language.

Wish you the best in your endeavor to learn and master C programming language!

About

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and 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 & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Sanfoundry Training Center of Excellence (CoE)

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and 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 & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.







Subscribe Newsletter & Posts
Sanfoundry Internships
Follow Manish & Sanfoundry