Govt. Exams
Entrance Exams
#include
int main() {
int x = 10, y = 20;
int *p = &x, *q = &y;
*p = *q;
printf("%d %d", x, y);
return 0;
}
*p = *q assigns the value of y (20) to x through the pointer p. So x becomes 20, y remains 20.
#include
int main() {
float f = 0.1 + 0.2;
if(f == 0.3)
printf("Equal");
else
printf("Not Equal");
return 0;
}
Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation.
struct Point {
char c;
int x;
double d;
}
Due to structure padding and alignment: char (1 byte) + padding (3 bytes) + int (4 bytes) + double (8 bytes) = 16 bytes.
7/2 performs integer division resulting in 3. Using %f format specifier prints it as 3.0 (or similar float representation).
Character constants in C use single quotes ('A'). Double quotes ("") are for string literals. A single character in double quotes is a string, not a character constant.
Attempting to modify a const variable results in a compilation error as const variables are read-only.
The * in the parameter declaration indicates that func takes a pointer to an integer, not an integer value.
strlen() returns size_t, which is an unsigned integer type used for sizes and counts.
Both #define and const can be used to define constants in C. #define is a preprocessor directive, while const is a type qualifier.
mutable is a C++ keyword, not a C keyword. extern, volatile, and register are valid C keywords.