C Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is C?

A

C is a general-purpose, procedural programming language developed by Dennis Ritchie in the early 1970s. It is widely used for system and application software.

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

What’s the difference between C and C++?

A

C is a procedural programming language, while C++ supports both procedural and object-oriented programming (OOP) features. C++ is an extension of C.

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

What is a complier?

A

A compiler is a tool that translates C source code into machine code or object code that the computer can execute.

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

What are header files in C?

A

Header files in C contain function declarations, macros, and definitions that can be included in multiple files using #include. Common examples are stdio.h, stdlib.h, etc.

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

What is the main() function in C?

A

The main() function is the entry point of every C program. It is where the execution of a C program begins.

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

What is #include <stdio.h>?</stdio.h>

A

It is a preprocessor directive that includes the standard input/output library, allowing the program to use functions like printf and scanf.

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

What is printf() used for?

A

printf() is used to print formatted output to the console.

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

What is scanf() used for?

A

scanf() is used for formatted input, allowing users to input values into variables.

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

What are variables in C?

A

Variables are containers that store data values. Each variable in C has a specific type which defines the kind of data it can hold.

The basic data types in C are:
int (integer)
float (floating-point numbers)
char (characters)
double (double-precision floating-point numbers)

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

What are pointers in C?

A

Pointers are variables that store memory addresses of other variables. They allow for dynamic memory allocation and manipulation of data at specific memory locations.

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

What is the purpose of return 0 in main()?

A

It indicates successful program execution. A return value of 0 typically means the program ran without errors.

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

What is a loop in C?

A

A loop is a control structure used to repeat a block of code multiple times. Common loops in C are for, while, and do-while loops.

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

What are conditional statements in C?

A

Conditional statements like if, else, and switch are used to execute different blocks of code based on whether a condition is true or false.

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

What is a function in C?

A

A function is a reusable block of code designed to perform a specific task. It is defined with a return type, function name, and parameters.

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

What is the difference between call by value and call by reference in C?

A

Call by value:
A copy of the variable’s value is passed to the function, and changes made within the function do not affect the original variable.

Call by reference:
A reference (memory address) is passed to the function, allowing changes made within the function to affect the original variable.

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

What are arrays in C?

A

Arrays are a collection of elements of the same data type stored in contiguous memory locations, accessed using an index.

17
Q

What is procedural programming?

A

Procedural programming is a paradigm that organizes code into procedures or functions. C is a procedural language, meaning it follows a step-by-step approach for task execution.

18
Q

What are the key differences between C and Java?

A

C is procedural, and Java is object-oriented.
C gives more control over system resources, but Java handles memory management automatically with garbage collection.
Java uses a virtual machine (JVM) for portability, while C compiles to machine code that is hardware-specific.

19
Q

What are the stages of the C compilation process?

A

Preprocessing: Handles directives like #include.
Compilation: Translates source code into object code.
Linking: Combines object code and libraries to create an executable.
Execution: The final executable runs on the system.

20
Q

What are preprocessor directives in C?

A

Preprocessor directives are instructions processed before compilation, such as #include for including files, and #define for defining constants.

21
Q

Write a basic “Hello World” program in C.

A

include <stdio.h></stdio.h>

int main() {
printf(“Hello World!\n”);
return 0;
}

22
Q

How does memory management differ between C and Java?

A

In C, memory is managed manually using functions like malloc and free, whereas Java automatically handles memory using garbage collection.

23
Q

What is stream-based I/O in C?

A

C provides functions like printf and scanf for stream-based input and output, handling data as a continuous flow.

24
Q

What does EXIT_SUCCESS in C indicate?

A

EXIT_SUCCESS is a macro defined in stdlib.h that indicates the program terminated successfully.

25
Q

What does EXIT_FAILURE in C indicate?

A

EXIT_FAILURE is a macro defined in stdlib.h that indicates the program failed or encountered an error.

26
Q

Why should EXIT_SUCCESS and EXIT_FAILURE be used instead of returning integer values directly?

A

Using EXIT_SUCCESS and EXIT_FAILURE ensures that your program is portable, readable, and compliant with the C/C++ standards. It’s a better approach than using raw integer values.