- What is the difference between
int
andfloat
data types in C?
- Answer:
int
is used for whole numbers (integers) whilefloat
is used for numbers with decimal points (floating-point numbers).
- What is the purpose of the
main
function in C?
- Answer: The
main
function is the entry point of a C program. Every C program execution begins from themain
function.
- How do you declare an array in C?
- Answer: You can declare an array by specifying its data type, size enclosed in square brackets, and a variable name. For example:
int numbers[10];
- Explain the syntax for a simple
if
statement in C.
- Answer:
if (condition) { // code to execute if condition is true } else { // code to execute if condition is false (optional) }
- What is the difference between the
=
and==
operators in C?
- Answer:
=
is the assignment operator used to assign a value to a variable.==
is the comparison operator used to check if two values are equal.
- What does the
break
statement do inside a loop in C?
- Answer: The
break
statement exits the loop immediately, even if the loop condition is still true.
- What is a pointer variable in C?
- Answer: A pointer variable stores the memory address of another variable. It allows you to indirectly access and modify the value of another variable.
- How do you read user input using
scanf
function in C?
- Answer: You can use
scanf
function with format specifiers like%d
for integers or%c
for characters to read user input and store it in variables.
- What are the different storage classes (auto, static, extern) in C?
- Answer: Storage classes define the scope and lifetime of variables.
auto
(default) creates a variable that exists only within its block scope.static
creates a variable that retains its value between function calls.extern
declares a variable that is defined in another file.
- What is the difference between compilation and execution in C programming?
- Answer: Compilation translates the C code into machine code understandable by the computer. Execution runs the machine code to perform the intended operations of the program.