Untitled Deck Flashcards
Who developed the C programming language and when?
C was developed by Dennis Ritchie at Bell Labs in 1972.
What is the main purpose of the C programming language?
C is a general-purpose, procedural programming language used for system programming, developing operating systems, and applications.
What are the basic data types in C?
The basic data types are:
- int (integer)
- float (floating-point number)
- char (character)
- double (double-precision floating-point number).
What is the role of the main()
function in a C program?
The main()
function is the entry point of every C program. The program execution starts from the main()
function.
What are comments in C, and how are they written?
Comments are used to make the code more readable and are ignored during execution.
- Single-line comment: // Comment here
- Multi-line comment: /* Comment here */
.
What are the different types of loops in C?
The types of loops are:
- for loop
- while loop
- do-while loop.
What is the difference between break
and continue
?
-
break
: Terminates the loop or switch statement immediately. -
continue
: Skips the rest of the current loop iteration and moves to the next iteration.
What is a switch
statement?
A switch
statement is a control statement that executes a block of code based on the value of an expression, typically using case
labels.
What is the difference between if
and else if
?
-
if
evaluates a condition and executes a block if the condition is true. -
else if
is used to test multiple conditions after an initialif
.
What is a function in C?
A function is a block of code that performs a specific task and can be reused.
What are the types of functions in C?
-
Library functions: Predefined functions like
printf()
andscanf()
. - User-defined functions: Functions created by the programmer.
What are function prototypes in C?
A function prototype declares the function name, return type, and parameters before its definition to inform the compiler about the function.
What is recursion in C?
Recursion is when a function calls itself directly or indirectly to solve smaller instances of a problem.
What is a pointer in C?
A pointer is a variable that stores the address of another variable.
How do you declare a pointer in C?
A pointer is declared using the *
symbol. Example: int *ptr;
What is the difference between malloc()
and calloc()
?
-
malloc()
: Allocates a single block of memory of a specified size and doesn’t initialize it. -
calloc()
: Allocates multiple blocks of memory and initializes them to zero.
What is NULL
in C?
NULL
is a macro representing a null pointer, indicating that the pointer does not point to any valid memory location.
How are arrays declared in C?
Arrays are declared as:datatype array_name[size];
Example: int arr[5];
What is the difference between a one-dimensional and a two-dimensional array?
- A one-dimensional array is a linear list of elements. Example:
int arr[5];
- A two-dimensional array is a table of elements with rows and columns. Example:
int arr[3][4];
.
How do you terminate a string in C?
Strings in C are terminated with the null character \0
.
What are the modes in file handling in C?
- “r”: Read mode
- “w”: Write mode
- “a”: Append mode
- “r+”: Read and write mode.
What are the standard file I/O functions in C?
fopen()
fclose()
fread()
fwrite()
fprintf()
-
fscanf()
.
What is the purpose of fclose()
?
The fclose()
function closes a file and frees associated resources.
What is the difference between #define
and const
?
-
#define
: Preprocessor directive for defining constants or macros. -
const
: Keyword to declare read-only variables.
What is the purpose of the return
statement?
The return
statement ends a function and optionally returns a value to the calling function.
What is the difference between struct
and union
?
-
struct
: Allocates memory for all members separately. -
union
: Allocates shared memory for all members, equal to the largest member.