Here are the most important Multiple choice questions(MCQ) on the basics of C programming. The MCQs are from the following sections,
- Introduction to C
- Data types
- Variables
- Constants
- Who invented C?
- Charles Babbage
- Bill Gates
- Dennis Ritchie
- Steve Jobs
Show Answer
Answer: C
C was invented by Dennis Ritchie at the Bell Laboratories in 1972.
- C is a …………………. type of language?
- Procedural
- Object-oriented
- Functional
- Bit-level
Show Answer
Answer: A
C is a procedural programming language. Its concept is based on procedure calls. Procedures are nothing but a series of computational steps to be carried out (functions, routines, or subroutines).
- Which of the following is not a valid variable name declaration in C?
- int Mark_1;
- int mark1;
- int __mark1;
- int 1mark;
Show Answer
Answer: D
Variable names must begin with an alphabet or an underscore.
- Find the output of the following C code?
- Hello world a
- Hello world 0
- Hello world followed by a random value
- Compile-time error
#include <stdio.h> int main() { printf("Hello world %d", a); return 0; }
Show Answer
Answer: D
The program will result in an error since the variable a is used without declaring it first. The output of the program will look like the following
hello.c: In function 'main': hello.c:3:30: error: 'a' undeclared (first use in this function) 3 | printf("Hello world %d", a); | ^ hello.c:3:30: note: each undeclared identifier is reported only once for each function it appears in
- Which of the following is not a valid variable name in C?
- mark
- number_1
- _count
- cash_$
Show Answer
Answer: D
Variable names can be made up of alphabets, digits, and the underscore character. No other special character is allowed.
- Which of the statement is true for naming variables in C?
- Variable names can be made up of alphabets, digits, and special characters.
- Variable names can begin with a digit.
- White spaces are not allowed in variable names.
- Variable names cannot contain the underscore character.
Show Answer
Answer: C
White spaces are not allowed in variable names in C.
- What will be the output of the following C code?
- Hello World 100
- Hello World 25
- Hello World followed by a random number
- Compile-time error
#include <stdio.h> int main() { int x = 100; int x = 25; printf("Hello World %d", y); return 0; }
Show Answer
Answer: D
Since the variable x is already defined, redefining it will cause a compile-time error. The output of the program will look like the following,
hello.c: In function 'main': hello.c:5:9: error: redefinition of 'x' 5 | int x = 25; | ^ hello.c:4:9: note: previous definition of 'x' was here 4 | int x = 100; | ^ hello.c:6:31: error: 'y' undeclared (first use in this function) 6 | printf("Hello World! %d", y); | ^ hello.c:6:31: note: each undeclared identifier is reported only once for each function it appears in
- Which of the following cannot be a variable name in C?
- marks_1
- teacher
- SCORE
- for
Show Answer
Answer: D
for is C keyword and keywords cannot be used a variable name.
- Determine the output of the following C code?
- 1147
- 1185
- Run time error
- Compile-time error
#include <stdio.h> int main() { int total_Marks = 1185; int total_marks = 1147; printf("%d", total_marks); return 0; }
Show Answer
Answer: A
1147
In C, Uppercase and lowercase letters are significant. That is, the variable total_Marks is not the same as total_marks.
- The format identifier “%d” is used for …………………. datatype?
- int
- char
- long
- float
Show Answer
Answer: A
%d and %i can be used as a format identifier for int data type.
- Which is the correct order of data types with respect to their size?
- int > char > float
- char > int > float
- char < double < int
- char < int < double
Show Answer
Answer: D
- Which of the following datatype has varying sizes?
- int
- double
- float
- struct
Show Answer
Answer: D
The size of a structure depends on its members.
- Which of the following is not a data type in C?
- int
- real
- float
- char
Show Answer
Answer: B
- Which of the following statement is true?
- ANSI C treats the variable ‘name’ and ‘Name’ to be the same.
- Character constants are coded using double-quotes.
- All variables must be given a type when they are declared.
- Any valid printable ANSII character can be used in an identifier.
Show Answer
Answer: C
All variables in C must be given a data type when they are declared.
- What will be the output of the following C code?
- pi is 3.14
- Compile-time error
- pi is followed by a random value
- Run time error
#include <stdio.h> int main() { const float pi; pi = 3.14; printf("pi is %f", pi); return 0; }
Show Answer
Answer: D
The code will result in a run time error because the constants have to be declared and initialized at the same time. The output of the program should be as follows,
pierror.c -lm pierror.c: In function 'main': pierror.c:5:12: error: assignment of read-only variable 'pi' 5 | pi = 3.14; | ^
- A global variable is also known as …………………. variable.
- external
- internal
- static
- dynamic
Show Answer
Answer: A
A global variable is also known as an external variable.
- Which of the following statement is true?
- Every line in a C program should end with a semicolon.
- Every C program ends with an END word.
- Comments cause the computer to print the text enclosed between /* and */ when executed.
- A
printf
statement can generate only one line of output
Show Answer
Answer: A
Every line in a C program should end with a semicolon.
- Identify the correct output for the following C code?
- Compile-time error.
- 8
- 8.0000000
- Garbage value
#include <stdio.h> void main() { int a = 8; float a = 8; printf("%d", a); }
Show Answer
Answer: A
Since the variable a is defined as both an integer and float, the code will result in an error. The output will be,
gcc multiple.c -lm multiple.c: In function 'main': multiple.c:5:11: error: conflicting types for 'a' 5 | float a = 4; | ^ multiple.c:4:9: note: previous definition of 'a' was here 4 | int a = 4; | ^ multiple.c:6:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'double' [-Wformat=] 6 | printf("%d", a); | ~^ ~ | | | | int double | %f
- Which of the following declaration is not supported in C?
- String str;
- int a;
- float pi=3.14;
- char *str;
Show Answer
Answer: A
The string data type is not supported in C.
- If an integer needs two bytes of storage, then the maximum value of an unsigned integer is
Show Answer
Answer: A
- If an integer needs two bytes of storage, then the maximum value of a signed integer is
Show Answer
Answer: B
In the signed magnitude form, one bit is used to store the sign(negative or positive). Only the remaining 15 bits are available to store the magnitude.
- The statement,
printf("%d",printf("hello"));
- results in a syntax error
- outputs hello5
- outputs garbage
- prints hello and terminates
Show Answer
Answer: B
Any function, including main(), returns a value to the calling environment. printf returns the number of characters it printed. So the output will be hello5 since it printed the five characters h, e, l, l, o.
- What will be the output of the following fragment of code if the input is abc,
- Syntax error
- Fatal error
- 3
- none of the above
#include <stdio.h> int main() { char x, y, z; printf ("%d", scanf("%c%c%c", &x, &y, &z )); return 0; }
Show Answer
Answer: C
Any function, including main(), returns a value to the calling environment. The scanf function returns the number of successful matches. In this case, 3.
- Choose the correct statements.
- An identifier may start with an underscore
- An identifier may end with an underscore
- IF is a valid identifier
- All of above
Show Answer
Answer: D
Since “IF” is written in upper case it is not a keyword.
- Which of the following are not keywords in C? :
- printf
- main
- IF
- All of above
Show Answer
Answer: C
Since “IF” is written in upper case it is not a keyword.