Untitled Deck Flashcards

1
Q

Who developed the C programming language and when?

A

C was developed by Dennis Ritchie at Bell Labs in 1972.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main purpose of the C programming language?

A

C is a general-purpose, procedural programming language used for system programming, developing operating systems, and applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the basic data types in C?

A

The basic data types are:
- int (integer)
- float (floating-point number)
- char (character)
- double (double-precision floating-point number).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the role of the main() function in a C program?

A

The main() function is the entry point of every C program. The program execution starts from the main() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are comments in C, and how are they written?

A

Comments are used to make the code more readable and are ignored during execution.
- Single-line comment: // Comment here
- Multi-line comment: /* Comment here */.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the different types of loops in C?

A

The types of loops are:
- for loop
- while loop
- do-while loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between break and continue?

A
  • break: Terminates the loop or switch statement immediately.
  • continue: Skips the rest of the current loop iteration and moves to the next iteration.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a switch statement?

A

A switch statement is a control statement that executes a block of code based on the value of an expression, typically using case labels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between if and else if?

A
  • if evaluates a condition and executes a block if the condition is true.
  • else if is used to test multiple conditions after an initial if.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a function in C?

A

A function is a block of code that performs a specific task and can be reused.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the types of functions in C?

A
  1. Library functions: Predefined functions like printf() and scanf().
  2. User-defined functions: Functions created by the programmer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are function prototypes in C?

A

A function prototype declares the function name, return type, and parameters before its definition to inform the compiler about the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is recursion in C?

A

Recursion is when a function calls itself directly or indirectly to solve smaller instances of a problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a pointer in C?

A

A pointer is a variable that stores the address of another variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you declare a pointer in C?

A

A pointer is declared using the * symbol. Example: int *ptr;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between malloc() and calloc()?

A
  • 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.
17
Q

What is NULL in C?

A

NULL is a macro representing a null pointer, indicating that the pointer does not point to any valid memory location.

18
Q

How are arrays declared in C?

A

Arrays are declared as:
datatype array_name[size];
Example: int arr[5];

19
Q

What is the difference between a one-dimensional and a two-dimensional array?

A
  • 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];.
20
Q

How do you terminate a string in C?

A

Strings in C are terminated with the null character \0.

21
Q

What are the modes in file handling in C?

A
  • “r”: Read mode
  • “w”: Write mode
  • “a”: Append mode
  • “r+”: Read and write mode.
22
Q

What are the standard file I/O functions in C?

A
  • fopen()
  • fclose()
  • fread()
  • fwrite()
  • fprintf()
  • fscanf().
23
Q

What is the purpose of fclose()?

A

The fclose() function closes a file and frees associated resources.

24
Q

What is the difference between #define and const?

A
  • #define: Preprocessor directive for defining constants or macros.
  • const: Keyword to declare read-only variables.
25
Q

What is the purpose of the return statement?

A

The return statement ends a function and optionally returns a value to the calling function.

26
Q

What is the difference between struct and union?

A
  • struct: Allocates memory for all members separately.
  • union: Allocates shared memory for all members, equal to the largest member.