What will be the output of the following code? int x = 5; float y = x; printf("%f", y);
A 5.000000 B Compilation error C 5 D Garbage value
Implicit type conversion occurs from int to float. The value 5 is converted to 5.0 and printed as 5.000000 with %f format specifier.
Which of the following occupies maximum memory in a 64-bit system?
A long int B long double C double D unsigned long long
In a 64-bit system, long double typically occupies 16 bytes (128 bits), which is the maximum among these options.
What is the range of unsigned int in a 32-bit system?
A 0 to 2^31 - 1 B 0 to 2^32 - 1 C -2^31 to 2^31 - 1 D 0 to 2^16 - 1
Unsigned int uses all 32 bits for magnitude, giving range 0 to 2^32 - 1 (0 to 4,294,967,295).
What is the difference between 'static' and 'extern' variables?
A static has global scope, extern has local scope B static has file scope, extern has global scope C No difference D static is for functions, extern is for variables
static restricts variable visibility to the current file; extern declares a variable defined elsewhere with global scope.
What is the output of the following code? int x = 10; int *p = &x; printf("%d", *p);
A 10 B Address of x C Garbage value D Compilation error
p is a pointer to x. *p dereferences the pointer, giving the value of x, which is 10.
Which variable storage class has default initialization to 0?
A auto B register C static D extern
Static variables are automatically initialized to 0 by the compiler.
What is the output of this code? float x = 2 5 ; printf("%f", x);
A 2.500000 B 2.000000 C 2 5 D Compilation error
2 5 performs integer division (both operands are int), resulting in 2. This is then converted to float as 2.0.
What happens when you declare a variable without initializing it?
A It's set to 0 automatically B It contains garbage value (for auto variables) C Compilation error occurs D It's set to NULL
Auto variables (local variables) contain unpredictable garbage values if not initialized. Static/global variables are initialized to 0.
Which data type is most suitable for storing a decimal number with high precision?
A float B double C long double D int
long double provides maximum precision (typically 80-128 bits) for decimal numbers compared to float (32 bits) and double (64 bits).
In C, which storage class has the longest scope and lifetime?
A auto B register C static D extern
extern variables have global scope and exist throughout program execution. They can be accessed across multiple files.
Which storage class variable is automatically initialized to 0 if not explicitly initialized?
A auto B register C static D extern
static variables are automatically initialized to 0 for numeric types and NULL for pointers if not explicitly initialized.
Consider: long long int x; What is the minimum guaranteed size of x according to C standard?
A 4 bytes B 8 bytes C 16 bytes D Compiler defined
According to C99 standard, long long int is guaranteed to be at least 8 bytes (64 bits).
Which of the following demonstrates proper type casting in C?
A (int) 5.7 B int(5.7) C int <- 5.7 D 5.7 as int
C uses C-style casting with parentheses: (type) expression. This converts 5.7 to integer 5.
What is the difference between 'signed' and 'unsigned' char in terms of range?
A No difference B signed: -128 to 127, unsigned: 0 to 255 C signed: 0 to 127, unsigned: -128 to 255 D signed: 0 to 256, unsigned: -128 to 128
Signed char uses 1 bit for sign, giving -128 to 127. Unsigned char uses all 8 bits for magnitude, giving 0 to 255.
Which keyword prevents a local variable from being optimized by compiler into a register?
A volatile B static C const D restrict
volatile tells compiler that a variable's value may change unexpectedly and should not be optimized. It's often used for hardware registers.
In the declaration 'int *p, q;', what are the data types of p and q?
A Both are pointers to int B p is pointer to int, q is int C Both are int D p is int, q is pointer to int
The * applies only to p. So p is int*, and q is int. To declare both as pointers: int *p, *q;
What happens when you attempt to store a double value in an int variable without explicit casting?
A Compilation error B Runtime error C The fractional part is silently truncated D The value is rounded
Implicit conversion truncates the fractional part. Modern compilers may warn but allow this. Example: int x = 5.9; results in x = 5.
Which of the following is a correct way to declare a constant variable in modern C?
A #define PI 3.14 B const float PI = 3.14; C PI = 3.14 (const); D constant float PI = 3.14;
Option B is the correct C99/C11 syntax. #define is preprocessing, while const is a type qualifier that provides type safety.
What is the output of: printf("%d", sizeof(char) + sizeof(int) + sizeof(float)); on a typical 32-bit system?
A 4 B 9 C 12 D 13
sizeof(char)=1, sizeof(int)=4, sizeof(float)=4 on 32-bit systems. Total: 1+4+4=9 bytes.
A variable declared with 'register' storage class suggests to the compiler to store it in:
A Main memory B CPU registers C Hard disk D Cache memory
register is a hint to compiler to store variable in CPU register for faster access. Compiler may ignore this if registers unavailable.