-
What is the primary purpose of the #include statement in C?
A) Define a new function
B) Declare a variable
C) Include a header file
D) Initialize a loop
Answer: C) Include a header file
-
Which preprocessor directive is used to include a standard C library header file?
A) #import
B) #include
C) #define
D) #ifdef
Answer: B) #include
-
In C programming, which symbol is used to enclose the header file name in a #include statement?
A) < >
B) " "
C) { }
D) ( )
Answer: A) < >
-
What does the #include statement do when it includes a header file in a C program?
A) Inserts the content of the header file into the source code
B) Declares a new function
C) Generates machine code
D) Comments out a block of code
Answer: A) Inserts the content of the header file into the source code
-
Which of the following is a valid #include statement to include a user-defined header file named "myheader.h"?
A) #include <myheader.h>
B) #include 'myheader.h'
C) #include "myheader.h"
D) #include <myheader.c>
Answer: C) #include "myheader.h"
-
What is the role of the C preprocessor in processing #include statements?
A) It compiles the included file separately
B) It resolves macros within the included file
C) It checks for syntax errors in the included file
D) It excludes the included file from compilation
Answer: B) It resolves macros within the included file
-
When including a header file, which option is typically used to specify the location of the file?
A) -L
B) -I
C) -H
D) -X
Answer: B) -I
-
Which of the following statements is true regarding the order of #include statements in a C program?
A) The order doesn't matter
B) They must be included after the main function
C) They must be included before any variable declarations
D) They must be included before any other preprocessor directives
Answer: A) The order doesn't matter
-
What happens if you include the same header file multiple times in a C program?
A) It leads to a compilation error
B) Only the first inclusion is considered, and subsequent inclusions are ignored
C) Each inclusion creates a separate copy of the file
D) The compiler automatically reorders the inclusions for optimization.
Answer: B) Only the first inclusion is considered, and subsequent inclusions are ignored.
-
Which of the following is an example of a standard C library header file?
A) math.h
B) program.c
C) myfunctions.h
D) main.c
Answer: A) math.h
-
How do you display text on the screen in C?
A) print()
B) display()
C) printf()
D) show()
Answer: C) printf()
-
What is the escape sequence used to print a newline character in C?
A) \n
B) \t
C) \r
D) \b
Answer: A) \n
-
Which function is used to display a single character in C?
A) putc()
B) putchar()
C) printc()
D) displaychar()
Answer: B) putchar()
-
To display the value of an integer variable `num`, which format specifier should be used in printf?
A) %s
B) %c
C) %d
D) %f
Answer: C) %d
-
What is the purpose of the escape sequence `\t` in printf?
A) Prints a tab character
B) Prints a backspace character
C) Prints a carriage return
D) Prints a double quote character
Answer: A) Prints a tab character
-
Which library should be included to use the printf function in C?
A) stdlib.h
B) math.h
C) conio.h
D) stdio.h
Answer: D) stdio.h
-
How do you print a floating-point number with two decimal places in C?
A) %f
B) %lf
C) %.2f
D) %.2lf
Answer: C) %.2f
-
What is the purpose of the `%c` format specifier in printf?
A) Used for printing integers
B) Used for printing floating-point numbers
C) Used for printing characters
D) Used for printing strings
Answer: C) Used for printing characters
-
To display the address of a variable `var`, which format specifier should be used in printf?
A) %d
B) %p
C) %a
D) %x
Answer: B) %p
-
What will be the output of the following code?
int x = 10;
printf("The value of x is %d\n", x);
A) The value of x is 10
B) The value of x is %d
C) The value of x is 0
D) There will be a compilation error
Answer: A) The value of x is 10
-
How do you read a character from the terminal in C?
A) `getch()`
B) `read_char()`
C) `scanf("%c", &ch)`
D) `getchar()`
Answer: D) `getchar()`
-
Which library should be included to use the `scanf` function for reading input in C?
A) `stdlib.h`
B) `stdio.h`
C) `conio.h`
D) `math.h`
Answer: B) `stdio.h`
-
To read an integer from the terminal in C, which format specifier should be used with `scanf`?
A) `%s`
B) `%c`
C) `%d`
D) `%f`
Answer: C) `%d`
-
What is the purpose of the `fgets` function in C for reading input?
A) Reads a single character
B) Reads a line of text
C) Reads a floating-point number
D) Reads an integer
Answer: B) Reads a line of text
-
How do you read a string with spaces in C using `scanf`?
A) You cannot read a string with spaces using `scanf`
B) Use `%s` format specifier
C) Use `%c` format specifier
D) Use `%S` format specifier
Answer: A) You cannot read a string with spaces using `scanf`
-
What function is commonly used to read an entire line of text from the terminal in C?
A) `getline()`
B) `readline()`
C) `getstring()`
D) `gets()`
Answer: A) `getline()`
-
How do you read a floating-point number from the terminal in C using `scanf`?
A) `%s`
B) `%c`
C) `%d`
D) `%f`
Answer: D) `%f`
-
Which function is used to read a single character without waiting for the user to press Enter in C?
A) `getchar()`
B) `getch()`
C) `read_char()`
D) `scanf("%c", &ch)`
Answer: B) `getch()`
-
What is the purpose of the `getchar` function in C?
A) Reads a string
B) Reads a line of text
C) Reads a single character
D) Reads an integer
Answer: C) Reads a single character
-
How do you read a formatted line of text from the terminal in C?
A) `scanf("%s", str)`
B) `gets(str)`
C) `fgets(str, size, stdin)`
D) `readline(str)`
Answer: C) `fgets(str, size, stdin)`
-
What is the primary purpose of data types in C?
A) To specify the memory size of variables
B) To define the order of execution of statements
C) To control the flow of program execution
D) To determine the number of loops in a program
Answer: A) To specify the memory size of variables
-
Which of the following is not a valid C data type?
A) int
B) char
C) real
D) float
Answer: C) real
-
What is the size (in bytes) of the `char` data type in C?
A) 1
B) 2
C) 4
D) 8
Answer: A) 1
-
Which data type is used to represent whole numbers in C?
A) int
B) float
C) double
D) char
Answer: A) int
-
Which data type is used to store characters in C?
A) char
B) int
C) double
D) float
Answer: A) char
-
What is the size (in bytes) of the `float` data type in C?
A) 2
B) 4
C) 8
D) 16
Answer: B) 4
-
Which data type is typically used for storing single-precision floating-point numbers in C?
A) float
B) double
C) long double
D) real
Answer: A) float
-
What is the size (in bytes) of the `double` data type in C?
A) 2
B) 4
C) 8
D) 16
Answer: C) 8
-
Which data type is used for storing boolean values in C?
A) bool
B) int
C) char
D) boolean
Answer: C) char
-
What is the size (in bytes) of the `long long` data type in C?
A) 2
B) 4
C) 8
D) 16
Answer: C) 8
-
What is a variable in C?
A) A constant value
B) A reserved keyword
C) A storage location with a name in which data can be stored and manipulated
D) A data type
Answer: C) A storage location with a name in which data can be stored and manipulated
-
Which of the following is a valid variable name in C?
A) 123variable
B) _myVariable
C) float
D) #myVariable
Answer: B) _myVariable
-
What is the purpose of declaring a variable in C?
A) To initialize it
B) To assign a value to it
C) To allocate memory for it
D) To create a constant
Answer: C) To allocate memory for it
-
Which keyword is used to declare a variable in C?
A) var
B) int
C) variable
D) declare
Answer: B) int
-
What does it mean to "initialize" a variable in C?
A) To give it a name
B) To declare it
C) To assign an initial value to it
D) To allocate memory for it
Answer: C) To assign an initial value to it
-
What is the data type of a variable that can store whole numbers in C?
A) integer
B) float
C) double
D) char
Answer: A) integer
-
Which of the following is a correct way to declare and initialize an integer variable with the value 42 in C?
A) int x = 42
B) int x = "42"
C) integer x = 42
D) x = 42
Answer: A) int x = 42
-
What is the scope of a local variable in C?
A) Limited to the function in which it is declared
B) Accessible from any function in the program
C) Limited to the block of code in which it is declared
D) Accessible from any file in the program
Answer: C) Limited to the block of code in which it is declared
-
Which of the following data types is used for storing characters in C?
A) character
B) str
C) string
D) char
Answer: D) char
-
How do you declare a constant variable in C?
A) Using the `var` keyword
B) Using the `constant` keyword
C) Using the `const` keyword
D) Constants cannot be declared in C
Answer: C) Using the `const` keyword
-
Which data type is used for storing decimal numbers with single precision in C?
A) float
B) double
C) long double
D) real
Answer: A) float
-
What is the size (in bytes) of the `double` data type in C?
A) 2
B) 4
C) 8
D) 16
Answer: C) 8
-
What is the maximum number of characters that a variable name can have in C?
A) 32
B) 64
C) 128
D) There is no fixed limit
Answer: D) There is no fixed limit
-
Which of the following is not a valid data type in C?
A) long long
B) real
C) short
D) char
Answer: B) real
-
How do you declare a global variable in C?
A) Prefix it with `static`
B) Prefix it with `global`
C) Declare it outside of any function
D) Use the `global` keyword
Answer: C) Declare it outside of any function
-
What happens if you declare a variable without initializing it in C?
A) The program will not compile
B) The variable will be initialized to 0 by default
C) The variable will contain a random value
D) It is not possible to declare a variable without initializing it
Answer: C) The variable will contain a random value
-
Which of the following is not a valid way to comment a line in C?
A) // This is a comment
B) /* This is a comment */
C) -- This is a comment
D) # This is a comment
Answer: C) -- This is a comment
-
What is the purpose of a data type in C?
A) To specify the number of decimal places in a number
B) To specify the size and type of data that can be stored in a variable
C) To specify the number of significant digits in a number
D) To specify the precision of a floating-point number
Answer: B) To specify the size and type of data that can be stored in a variable
-
In C, which data type is used to represent true or false values?
A) boolean
B) bool
C) char
D) int
Answer: C) char
-
What is the size (in bytes) of the `long long` data type in C?
A) 2
B) 4
C) 8
D) 16
Answer: C) 8