C- Declarations and Initializations Questions and Answers

Practice Mode
Showing 10 of 49 questions
Q11
What is the default value of an uninitialized local variable in C?
  • A 0
  • B NULL
  • C Garbage value
  • D 1
Answer: Option C
Explanation: Local variables are not automatically initialized and contain garbage values.
Q12
Which keyword is used to define a constant in C?
  • A constant
  • B define
  • C const
  • D fixed
Answer: Option C
Explanation: const keyword makes a variable read-only after initialization.
Q13
What is the size of int data type in C?
  • A 2 bytes
  • B 4 bytes
  • C 8 bytes
  • D Compiler dependent
Answer: Option D
Explanation: The size of int depends on the system architecture and compiler.
Q14
Which of the following is not a valid C identifier?
  • A my_var
  • B _var
  • C 2ndvar
  • D var2
Answer: Option C
Explanation: Identifiers cannot start with numbers or contain special characters.
Q15
What does the extern keyword do?
  • A Defines a new variable
  • B Declares a variable defined elsewhere
  • C Makes variable constant
  • D Allocates memory for variable
Answer: Option B
Explanation: extern declares a variable without defining it, indicating it is defined elsewhere.
Q16
Which storage class has the longest lifetime?
  • A auto
  • B register
  • C static
  • D extern
Answer: Option C
Explanation: static variables persist throughout the program execution.
Q17
What is the output of: printf("%d", sizeof(char));
  • A 1
  • B 2
  • C 4
  • D 8
Answer: Option A
Explanation: char always takes 1 byte in C regardless of the system.
Q18
Which of the following is a valid way to declare and initialize a string?
  • A char str[] = "Hello";
  • B char str = "Hello";
  • C string str = "Hello";
  • D char *str = 'H';
Answer: Option A
Explanation: Strings can be initialized using array syntax or pointer with string literal.
Q19
What is the value of an uninitialized global variable?
  • A 0
  • B Garbage value
  • C NULL
  • D Undefined
Answer: Option A
Explanation: Global variables are automatically initialized to zero by default.
Q20
Which of the following is a valid floating point declaration?
  • A float f = 3.14;
  • B float f = 3.14f;
  • C double d = 3.14;
  • D All of the above
Answer: Option D
Explanation: float and double are used for floating point numbers in C.
Questions and Answers for Competitive Exams Various Entrance Test