C Programming Quiz

C is the foundation of many other languages and of operating systems. This quiz checks syntax, data types, operators, control statements, functions, arrays, pointers and memory.

What this quiz covers

Study tip: Trace each code question by hand, writing down variable values line by line, before you pick an answer.

Questions, answers and explanations

1. Who is the father of C language?

  1. Steve Jobs
  2. James Gosling
  3. Dennis Ritchie
  4. Rasmus Lerdorf

Answer: Dennis Ritchie

Dennis Ritchie developed the C programming language at Bell Labs.

2. Which of the following is not a valid C variable name?

  1. int number;
  2. float rate;
  3. int variable_count;
  4. int $main;

Answer: int $main;

The ' symbol is not allowed in standard C variable names.

3. All keywords in C are in ____________.

  1. LowerCase letters
  2. UpperCase letters
  3. CamelCase letters
  4. None of the mentioned

Answer: LowerCase letters

All C language keywords are written in lowercase.

4. Which of the following is true for variable names in C?

  1. They can contain alphanumeric characters as well as special characters
  2. It is not an error to declare a variable to be one of the keywords
  3. Variable names cannot start with a digit
  4. Variable can be of any length

Answer: Variable names cannot start with a digit

A C variable name must begin with a letter or underscore.

5. Which is a valid C expression?

  1. int my_num = 100,000;
  2. int my_num = 100000;
  3. int my num = 1000;
  4. int $my_num = 10000;

Answer: int my_num = 100000;

Variable names cannot contain spaces or ' , and commas are not allowed in numbers.

6. Which of the following cannot be a variable name in C?

  1. volatile
  2. true
  3. friend
  4. export

Answer: volatile

'volatile' is a reserved keyword in C.

7. What is short int in C programming?

  1. The basic data type of C
  2. Qualifier
  3. Short is the qualifier and int is the basic data type
  4. All of the mentioned

Answer: Short is the qualifier and int is the basic data type

'short' modifies the size of the int data type.

8. Which declaration is not supported by C language?

  1. String str;
  2. char *str;
  3. float str = 3e2;
  4. Both String str; and float str = 3e2;

Answer: String str;

C has no built-in String data type.

9. Which keyword prevents changes to a variable in C?

  1. immutable
  2. mutable
  3. const
  4. volatile

Answer: const

The const keyword makes a variable read-only.

10. What is the result of a logical or relational expression in C?

  1. True or False
  2. 0 or 1
  3. 0 if false and any positive number if true
  4. None of the mentioned

Answer: 0 or 1

Relational and logical expressions return either 0 (false) or 1 (true).

11. Which typecasting is accepted in C?

  1. Widening conversions
  2. Narrowing conversions
  3. Widening & Narrowing conversions
  4. None of the mentioned

Answer: Widening & Narrowing conversions

C supports both widening and narrowing type conversions.

12. Where in C does operator precedence not exist?

  1. Within conditional statements
  2. Within while and do-while
  3. Within a macro definition
  4. None of the mentioned

Answer: Within a macro definition

Macros are expanded by the preprocessor before compilation.

13. Which of the following is NOT possible with any two operators in C?

  1. Different precedence, same associativity
  2. Different precedence, different associativity
  3. Same precedence, different associativity
  4. All of the mentioned

Answer: Same precedence, different associativity

Operators with the same precedence always share the same associativity.

14. What is an example of iteration in C?

  1. for
  2. while
  3. do-while
  4. all of the mentioned

Answer: all of the mentioned

All three are looping (iteration) statements.

15. Functions can return enumeration constants in C?

  1. true
  2. false
  3. depends on the compiler
  4. depends on the standard

Answer: true

Functions can return values of enum types.

16. Functions in C language are always _________.

  1. Internal
  2. External
  3. Both Internal and External
  4. External and Internal are not valid terms for functions

Answer: External

Functions in C have external linkage by default.

17. Which of the following is not accepted in C?

  1. static a = 10;
  2. static int func(int);
  3. static static int a;
  4. all of the mentioned

Answer: static static int a;

The 'static' keyword cannot be repeated.

18. The property that allows different executables for different platforms is called?

  1. File inclusion
  2. Selective inclusion
  3. Conditional compilation
  4. Recursive macros

Answer: Conditional compilation

Conditional compilation allows platform-specific code.

19. What is #include <stdio.h>?

  1. Preprocessor directive
  2. Inclusion directive
  3. File inclusion directive
  4. None of the mentioned

Answer: Preprocessor directive

#include is handled by the C preprocessor before compilation.

20. C preprocessors can have compiler-specific features.

  1. True
  2. False
  3. Depends on the standard
  4. Depends on the platform

Answer: True

Many C compilers provide their own preprocessor extensions.

Take the timed quiz