1.
Which of the following is not a valid variable name declaration?
Correct Answer
B. Int 3_a;
Explanation
The variable name "3_a" is not a valid declaration because it starts with a number. In programming, variable names cannot begin with a number, they must start with a letter or an underscore.
2.
All keywords in C are in?
Correct Answer
C. Lower Case letters
Explanation
In the C programming language, all keywords are written in lower case letters. This is a standard convention followed in C programming to differentiate keywords from user-defined identifiers. Using lower case letters for keywords helps in maintaining code readability and consistency.
3.
What is the output of this C code?
int main()
{
int i = -5;
int k = i %4;
printf("%d\n", k);
}
Correct Answer
B. -1
Explanation
The code snippet declares two integer variables, i and k. The value of i is initialized to -5. The value of k is assigned the result of i modulo 4, which is -1. The printf statement then prints the value of k, which is -1. Therefore, the output of this C code is -1.
4.
What is the value of x in this C code?
void main()
{
int x = 4 *5 / 2 + 9;
}
Correct Answer
C. 19
Explanation
The value of x in the given C code is 19. This is because the expression "4 * 5 / 2 + 9" is evaluated from left to right according to the order of operations. First, the multiplication "4 * 5" is performed, resulting in 20. Then, the division "20 / 2" is performed, resulting in 10. Finally, the addition "10 + 9" is performed, resulting in 19.
5.
What is the output of this C code?
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
Correct Answer
D. 11,11
Explanation
The code declares a pointer variable 'ptr' and an integer variable 'a' with a value of 10. 'ptr' is then assigned the address of 'a'. The line '*ptr += 1' increments the value at the memory location pointed to by 'ptr' by 1, which means 'a' is also incremented by 1. The printf statement prints the value at the memory location pointed to by 'ptr' (which is now 11) and the value of 'a' (which is also 11). Therefore, the output of the code is 11,11.
6.
What is the size of an int data type?
Correct Answer
C. Depends on the system/compiler
Explanation
The size of an int data type depends on the system/compiler. Different systems and compilers may have different sizes for the int data type. Therefore, the size cannot be determined without knowing the specific system/compiler being used.
7.
What is short int in C programming?
Correct Answer
C. Short is the qualifier and int is the basic datatype
Explanation
In C programming, a short int is a data type that is a combination of a qualifier and a basic data type. The "short" is the qualifier, indicating that the variable will take up less memory than a regular int. The "int" is the basic data type, specifying that the variable will store integer values. Therefore, the correct answer is that short is the qualifier and int is the basic data type.
8.
Which of the datatypes have a size that is variable?
Correct Answer
C. Struct
Explanation
Struct is a datatype that allows the grouping of different variables under one name, creating a composite data type. Unlike other datatypes like double, int, and float, the size of a struct is variable and depends on the size of its individual members. This means that the size of a struct can be different based on the types and sizes of its members, making it a datatype with variable size.
9.
What is the output of this C code?
int main()
{
int x = 1;
int y = x == 1 ? getchar(): 2;
printf("%d\n", y);
}
Correct Answer
C. Ascii value of character getchar function returns
Explanation
The code initializes the variable x to 1. It then uses the ternary operator to check if x is equal to 1. Since it is true, the code executes the getchar() function, which reads a character from the user. The getchar() function returns the ASCII value of the character. Therefore, the output of the code will be the ASCII value of the character read by getchar().
10.
#include is called
Correct Answer
A. Preprocessor directive
Explanation
The given correct answer is "Preprocessor directive" because the #include statement is a preprocessor directive in C and C++ programming languages. It is used to include the content of another file in the current file during the compilation process. The preprocessor scans the source code before the actual compilation and replaces the #include statement with the content of the specified file. This allows for code reuse and modular programming by including header files that contain function prototypes, definitions, and other necessary declarations.
11.
C preprocessors can have compiler-specific features.
Correct Answer
A. True
Explanation
C preprocessors can have compiler-specific features because the preprocessor directives in C are evaluated by the compiler before the actual compilation process begins. This allows the preprocessor to have knowledge of the specific features and extensions provided by the compiler. Therefore, different compilers may have their own unique set of preprocessor features and behaviors, making it possible for C preprocessors to have compiler-specific features.
12.
Which of the following are C preprocessors?
Correct Answer
D. All of the mentioned.
Explanation
The given answer is "All of the mentioned." This means that all of the options listed (#ifdef, #define, #endif) are C preprocessors. C preprocessors are directives that are processed by the C preprocessor before the compilation of the code. #ifdef is used to check if a macro is defined, #define is used to define a macro, and #endif is used to end a conditional block. Therefore, all of these options are valid C preprocessors.
13.
#include statement must be written:
Correct Answer
C. Before any scanf/printf
Explanation
The #include statement must be written before any scanf/printf because it is used to include header files in the program. Header files contain important function declarations and definitions that are needed for the program to compile and run correctly. Therefore, the #include statement should be placed at the beginning of the program, before any functions or statements that rely on the functions declared in the header files.
14.
The C-preprocessors are specified with _________symbol.
Correct Answer
A. #
Explanation
The C-preprocessors are specified with the # symbol. This symbol is used to indicate that the following line is a preprocessor directive, which is a command that is processed before the code is compiled. Preprocessor directives are used to include header files, define macros, and perform other tasks that are necessary for the compilation process.
15.
Does this compile without error?
int main()
{
for (int k = 0; k < 10; k++);
return 0;
}
Correct Answer
A. Yes
Explanation
The given code will compile without error. The code defines a main function and uses a for loop to iterate from 0 to 9. The loop body is empty, indicated by the semicolon immediately following the closing parenthesis of the for loop. After the loop, the code returns 0. Since there are no syntax errors or logical issues in the code, it will compile successfully without any errors.