Basics of C:
-
What is C?
- Answer: C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in the 1970s.
-
What is the difference between
int
andfloat
data types?- Answer:
int
is used for integer values, whilefloat
is used for floating-point (decimal) values.
- Answer:
-
Explain the difference between
printf()
andscanf()
functions.- Answer:
printf()
is used for output (printing to the console), whilescanf()
is used for input (reading from the console).
- Answer:
Variables and Data Types:
-
What is a variable?
- Answer: A variable is a named location in memory that stores a value.
-
What is the size of the
int
data type in C?- Answer: The size of
int
varies by system architecture but is typically 4 bytes.
- Answer: The size of
-
Explain the
sizeof
operator.- Answer:
sizeof
returns the size, in bytes, of a variable or data type.
- Answer:
Control Flow:
-
What is the purpose of the
if
statement in C?- Answer: The
if
statement is used for conditional execution of code based on a specified condition.
- Answer: The
-
Explain the difference between
while
anddo-while
loops.- Answer:
while
tests the condition before the loop, whiledo-while
tests it after the loop.
- Answer:
-
What is a
switch
statement used for?- Answer: A
switch
statement is used for multi-way branching based on the value of an expression.
- Answer: A
Functions:
-
What is a function in C?
- Answer: A function is a block of code that performs a specific task.
-
Explain the difference between actual parameters and formal parameters.
- Answer: Actual parameters are passed to a function during a function call, while formal parameters are used within the function.
-
What is recursion?
- Answer: Recursion is a technique where a function calls itself directly or indirectly to solve a problem.
Arrays and Pointers:
-
What is an array in C?
- Answer: An array is a collection of elements of the same data type stored in contiguous memory locations.
-
Explain the concept of a pointer.
- Answer: A pointer is a variable that holds the memory address of another variable.
-
How do you dynamically allocate memory in C?
- Answer: Use the
malloc()
function to dynamically allocate memory.
- Answer: Use the
Strings:
-
What is a string in C?
- Answer: A string is an array of characters terminated by a null character
\0
.
- Answer: A string is an array of characters terminated by a null character
-
How do you compare two strings in C?
- Answer: Use the
strcmp()
function to compare two strings.
- Answer: Use the
Structures and Unions:
-
What is a structure in C?
- Answer: A structure is a user-defined data type that groups related data members under one name.
-
Explain the concept of a union.
- Answer: A union is a user-defined data type that allows storing different data types in the same memory location.
File Handling:
-
What is a file in C?
- Answer: A file is a collection of data stored on a secondary storage device.
-
How do you open a file in C?
- Answer: Use the
fopen()
function to open a file.
- Answer: Use the
-
Explain the purpose of the
fclose()
function.- Answer:
fclose()
is used to close a file that was opened usingfopen()
.
- Answer:
Memory Management:
- What is the purpose of the
free()
function?- Answer:
free()
is used to deallocate memory previously allocated bymalloc()
or related functions.
- Answer:
Preprocessor Directives:
-
What is a preprocessor directive?
- Answer: A preprocessor directive is a command that starts with a
#
symbol, and it is executed before the actual compilation.
- Answer: A preprocessor directive is a command that starts with a
-
What is the purpose of
#include
in C?- Answer:
#include
is used to include the content of a file during the preprocessing stage.
- Answer:
Bitwise Operations:
-
What are bitwise operations?
- Answer: Bitwise operations manipulate individual bits of binary numbers.
-
Explain the
&
(bitwise AND) operator.- Answer:
&
performs a bitwise AND operation.
- Answer:
Dynamic Memory Allocation:
-
What is dynamic memory allocation in C?
- Answer: Dynamic memory allocation allows a program to allocate memory at runtime.
-
How do you allocate memory for an array dynamically?
- Answer: Use the
malloc()
function.
- Answer: Use the
Enumerations:
- What is an enumeration in C?
- Answer: An enumeration is a user-defined data type that consists of named integer constants.
Miscellaneous:
-
What is the purpose of the
sizeof
operator in C?- Answer:
sizeof
returns the size, in bytes, of a variable or data type.
- Answer:
-
Explain the purpose of the
const
keyword.- Answer:
const
is used to declare constants, and it indicates that the variable's value cannot be changed.
- Answer:
-
What is the difference between
++i
andi++
?- Answer: Both increment the value of
i
by 1, but++i
is the pre-increment operator, andi++
is the post-increment operator.
- Answer: Both increment the value of
-
Explain the
typedef
keyword.- Answer:
typedef
is used to create an alias for existing data types.
- Answer:
-
What is the purpose of the
return
statement in a function?- Answer: The
return
statement is used to specify the value a function should return.
- Answer: The
-
What is the purpose of the
break
statement?- Answer: The
break
statement is used to exit from a loop or switch statement.
- Answer: The
-
Explain the difference between
NULL
and0
.- Answer:
NULL
is a macro representing a null pointer, while0
is the integer literal zero.
- Answer:
-
What is a comment, and how do you write comments in C?
- Answer: Comments are explanatory notes in the code. In C, you can use
//
for single-line comments and/* */
for multi-line comments.
- Answer: Comments are explanatory notes in the code. In C, you can use
-
What is the purpose of the
continue
statement?- Answer: The
continue
statement is used to skip the rest of the loop and move to the next iteration.
- Answer: The
-
Explain the concept of a constant pointer.
- Answer: A constant pointer is a pointer whose address cannot be changed but the value it points to can be modified.
Comments