C Flashcards
What is C?
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.
What’s the difference between C and C++?
C is a procedural programming language, while C++ supports both procedural and object-oriented programming (OOP) features. C++ is an extension of C.
What is a complier?
A compiler is a tool that translates C source code into machine code or object code that the computer can execute.
What are header files in C?
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.
What is the main() function in C?
The main() function is the entry point of every C program. It is where the execution of a C program begins.
What is #include <stdio.h>?</stdio.h>
It is a preprocessor directive that includes the standard input/output library, allowing the program to use functions like printf and scanf.
What is printf() used for?
printf() is used to print formatted output to the console.
What is scanf() used for?
scanf() is used for formatted input, allowing users to input values into variables.
What are variables in C?
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)
What are pointers in C?
Pointers are variables that store memory addresses of other variables. They allow for dynamic memory allocation and manipulation of data at specific memory locations.
What is the purpose of return 0 in main()?
It indicates successful program execution. A return value of 0 typically means the program ran without errors.
What is a loop in C?
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.
What are conditional statements in C?
Conditional statements like if, else, and switch are used to execute different blocks of code based on whether a condition is true or false.
What is a function in C?
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.
What is the difference between call by value and call by reference in C?
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.
What are arrays in C?
Arrays are a collection of elements of the same data type stored in contiguous memory locations, accessed using an index.
What is procedural programming?
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.
What are the key differences between C and Java?
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.
What are the stages of the C compilation process?
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.
What are preprocessor directives in C?
Preprocessor directives are instructions processed before compilation, such as #include for including files, and #define for defining constants.
Write a basic “Hello World” program in C.
include <stdio.h></stdio.h>
int main() {
printf(“Hello World!\n”);
return 0;
}
How does memory management differ between C and Java?
In C, memory is managed manually using functions like malloc and free, whereas Java automatically handles memory using garbage collection.
What is stream-based I/O in C?
C provides functions like printf and scanf for stream-based input and output, handling data as a continuous flow.
What does EXIT_SUCCESS in C indicate?
EXIT_SUCCESS is a macro defined in stdlib.h that indicates the program terminated successfully.
What does EXIT_FAILURE in C indicate?
EXIT_FAILURE is a macro defined in stdlib.h that indicates the program failed or encountered an error.
Why should EXIT_SUCCESS and EXIT_FAILURE be used instead of returning integer values directly?
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.