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
intandfloatdata types?- Answer:
intis used for integer values, whilefloatis 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
intdata type in C?- Answer: The size of
intvaries by system architecture but is typically 4 bytes.
- Answer: The size of
-
Explain the
sizeofoperator.- Answer:
sizeofreturns the size, in bytes, of a variable or data type.
- Answer:
Control Flow:
-
What is the purpose of the
ifstatement in C?- Answer: The
ifstatement is used for conditional execution of code based on a specified condition.
- Answer: The
-
Explain the difference between
whileanddo-whileloops.- Answer:
whiletests the condition before the loop, whiledo-whiletests it after the loop.
- Answer:
-
What is a
switchstatement used for?- Answer: A
switchstatement 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
#includein C?- Answer:
#includeis 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
sizeofoperator in C?- Answer:
sizeofreturns the size, in bytes, of a variable or data type.
- Answer:
-
Explain the purpose of the
constkeyword.- Answer:
constis used to declare constants, and it indicates that the variable's value cannot be changed.
- Answer:
-
What is the difference between
++iandi++?- Answer: Both increment the value of
iby 1, but++iis the pre-increment operator, andi++is the post-increment operator.
- Answer: Both increment the value of
-
Explain the
typedefkeyword.- Answer:
typedefis used to create an alias for existing data types.
- Answer:
-
What is the purpose of the
returnstatement in a function?- Answer: The
returnstatement is used to specify the value a function should return.
- Answer: The
-
What is the purpose of the
breakstatement?- Answer: The
breakstatement is used to exit from a loop or switch statement.
- Answer: The
-
Explain the difference between
NULLand0.- Answer:
NULLis a macro representing a null pointer, while0is 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
continuestatement?- Answer: The
continuestatement 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