1.
Which of the following is a keyword used for a storage class?
Correct Answer
C. Auto
Explanation
The keyword "auto" is used for a storage class in programming. It is used to declare a local variable within a function, which automatically gets allocated and deallocated memory when the function is called and finished executing. This keyword is used to define variables that have a local scope and are automatically initialized to garbage values.
2.
The minimum and maximum number that can be represented by int type variable are respectively
Correct Answer
D. −32768 to +32767
Explanation
The correct answer is −32768 to +32767. This is because an int type variable in most programming languages uses 2 bytes of memory, allowing it to store values from -32768 to +32767. The range starts at -32768 because one of the bits is used to represent the sign of the number. The range ends at +32767 because the remaining 15 bits are used to represent the magnitude of the number, which allows for a maximum value of 2^15 - 1.
3.
Which operator has the lowest priority?
Correct Answer
A. ++
Explanation
The operator with the lowest priority is ++. This is because ++ is a unary operator and it has the highest precedence among unary operators, but it has lower precedence compared to other operators like % and +.
4.
The conversion character corresponding to hexadecimal integer is
Correct Answer
D. %hd
Explanation
The conversion character %hd is the correct answer because it is used to format and print a signed short integer in hexadecimal format. The "h" in %hd represents the "short" data type, which is a 2-byte integer. The "d" in %hd indicates that the integer should be printed in hexadecimal format.
5.
By default a function returns a value of type
Correct Answer
A. Int
Explanation
By default, a function in many programming languages, including C and C++, returns a value of type int. This means that when a function is called, it will perform its operations and then return an integer value as its result. However, it is also possible for a function to have a return type of char or void, depending on the specific requirements of the program. In this case, the correct answer is int, indicating that the default return type of a function is an integer.
6.
What will be the output of the following C code?
void main()
{
int a;
a=−8%−11;
printf("%d",a);
}
Correct Answer
C. -8
Explanation
The code calculates the remainder when -8 is divided by -11 using the modulus operator (%). Since -8 divided by -11 is -1 with a remainder of -8, the output of the code will be -8.
7.
C is a _______________ language
Correct Answer
A. High Level
Explanation
The correct answer is "High Level." This means that the language C is designed to be user-friendly and abstracted from the underlying hardware. It provides a higher level of abstraction compared to low-level languages like assembly or machine code, making it easier for programmers to write and understand code.
8.
What will be the output of the following C code?
void main()
{
int a;
a=5/−2;
printf("%d",a);
}
Correct Answer
C. -2
Explanation
The code snippet calculates the value of "a" by dividing 5 by -2. In C, integer division truncates any decimal places and only returns the whole number part. Therefore, the result of 5 divided by -2 is -2. The printf statement then prints the value of "a", which is -2.
9.
Which of the following is not a character constant?
Correct Answer
D. All of the above
10.
What will be the output of the following C code?
void main()
{
float b;
a=5.0%2;
printf("%f",b);
}
Correct Answer
D. Compilation Error
Explanation
The code will result in a compilation error because the variable "a" is not declared before it is used.
11.
What will be the output of the following C code?
void main()
{
int a=2, b;
b=a++*++a;
printf("a=%d,b=%d",a,b);
}
Correct Answer
A. a=4, b=9
Explanation
In the given code, the value of 'a' is initially 2. The expression 'a++' is post-increment, so the value of 'a' is used first and then incremented by 1. The expression '++a' is pre-increment, so the value of 'a' is incremented by 1 first and then used in the expression. Therefore, the value of 'b' will be 2 * 3 = 6. After the expression is evaluated, the value of 'a' becomes 4. So, the final output will be "a=4, b=6".
12.
What will be the output of the following C code?
void main()
{
int a=4;
printf("%d %d %d”, ++a, a, a++);
}
Correct Answer
A. 654
Explanation
The output of the given code will be 654. This is because the expression `++a` increments the value of `a` before it is printed, so `a` becomes 5. Then, when `a` is printed again, it is still 5. Finally, the expression `a++` increments the value of `a` after it is printed, so it becomes 6 but is not printed. Therefore, the output is 654.
13.
What will be the output of the following C code?
void main()
{
int a=2;
a=++a*a++*++a;
printf("a=%d”,a);
}
Correct Answer
A. A=65
Explanation
In the given code, the expression `++a*a++*++a` is evaluated. The order of evaluation is from left to right. Initially, `a` is 2.
First, `++a` increments `a` to 3. Then, `a` is multiplied by `a++`. The value of `a` is now 3, so the result is 3 * 3 = 9.
Next, `a` is incremented again to 4. Finally, `a` is multiplied by `++a`, which is now 4. The result is 4 * 4 = 16.
Therefore, the value of `a` is 16. The correct answer is a=16.
14.
What will be the output of the following C code?
void main()
{
int i = 1;
printf(“%d %d %d”,i++,i,++i);
}
Correct Answer
B. 2 2 2
Explanation
The output of the code will be "2 2 2". This is because the order of evaluation of the arguments in the printf statement is not guaranteed in C. In this case, the order in which the arguments are evaluated is undefined behavior. Therefore, the values of i can be different at different points during the evaluation, leading to inconsistent results.
15.
What will be the output of the following C code?
void main()
{
int i;
i = −1 < 20 >100;
printf(“%d”,i);
}
Correct Answer
A. 0
Explanation
In the given code, the expression "-1 < 20" is evaluated first. This expression is true because -1 is less than 20. The result of this expression is 1. Then, the expression "1 > 100" is evaluated. This expression is false because 1 is not greater than 100. The result of this expression is 0. Therefore, the value of i is 0. When the value of i is printed using printf, the output will be 0.
16.
What will be the output of the following C code?
void main()
{
unsigned int a=1;
printf(“%d”,a
Correct Answer
A. 0
Explanation
The output of the given C code will be 0. The code initializes an unsigned integer variable 'a' with the value 1. In the printf statement, the expression 'a
17.
What will be the output of the following C code?
void main()
{
int i;
i = 3^2;
printf(“%d”,i);
}
Correct Answer
D. 1
Explanation
The code uses the bitwise XOR operator (^) to perform an operation on the numbers 3 and 2. The XOR operator compares the binary representation of the two numbers and returns a new number with bits set where the corresponding bits of the two numbers are different. In this case, 3 is represented as 0011 in binary and 2 is represented as 0010. The XOR operation will result in 0001, which is equivalent to 1 in decimal. Therefore, the output of the code will be 1.
18.
What will be the output of the following C code?
void main()
{
int i;
i = !5;
printf(“%d”,i);
}
Correct Answer
A. 0
Explanation
The code snippet initializes the variable 'i' with the logical negation of the value 5. In C, any non-zero value is considered as true, and the logical negation of true is false, which is represented by the value 0. Therefore, the output of the code will be 0.
19.
What will be the output of the following C code?
void main()
{
int i;
i = !−5;
printf(“%d”,i);
}
Explanation
The output of the given code will be 1. In the code, the variable i is assigned the value of the logical NOT operator applied to -5. The logical NOT operator returns 0 if the operand is non-zero and 1 if the operand is zero. Since -5 is non-zero, the logical NOT operator returns 0, which is then assigned to i. When the value of i is printed using the printf() function, it will display 0.
20.
What will be the output of the following C code?
void main()
{
int x, y, z;
x = y = z = 1;
printf(“%d”, x + y + z);
}
Correct Answer
B. 3
Explanation
The code initializes three variables, x, y, and z, to the value 1. Then, it prints the sum of these three variables, which is 3.