C Programming
C Programming
C Programming
Description
printf()
include <stdio.h>
int main() {
return 0;
Explanation
Command
Description
#include <stdio.h>
It is a preprocessor command which consists of a standard input output header
file(stdio.h) before compiling a C program.
int main()
/*_some_comments_*/
Any content inside “/* */” will not be used for compilation and execution.
printf(“Hello_World! “);
getch();
return 0;
Terminates a C program or main function and returns 0.
Command
Description
printf()
scanf()
if
while
do-while
Repeatedly executes a block of code at least once and then continues to execute
the block as long as a condition is true.
for
switch
Tests a variable against a series of case statements and executes a block of code
corresponding to the first matching case.
break
Skips the current iteration of a loop and continues with the next iteration.
return
typedef
struct
Defines a composite data type that groups together variables of different types.
enum
#define
Defines a macro that can replace text in the source code with a predefined value.
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
2. Compiling the code: Once it has been written, we need to compile it using a C
compiler. For example, we might use the GCC compiler on a Linux system. We
would run the following command from the terminal:
3. Linking the code: In this step, the C compiler may link our code with any
necessary libraries or other code modules. Our simple "Hello, world!" program
requires no additional libraries, so this step is relatively straightforward.
4. Running the program: With our program compiled and linked, we can now run
it. On a Linux system, we would run the following command from the terminal:
./hello_world
This would execute the hello_world binary and print the message "Hello, world!"
to the console.
5. Input and output: In our "Hello, world!" program, there is no input required,
and the only output is the message printed to the console.
6. Memory management: Our simple program does not require dynamic memory
allocation or deallocation, so memory management is not a concern.
7. Debugging and testing: Finally, we want to test and debug our program to
ensure it is working correctly. For a simple program like this, we might manually
run it and verify that the output is correct. For more complex programs, we might
use debugging tools like gdb or automated testing frameworks to help identify
and fix issues.
Command
scanf()
if
else
while
Repeatedly executes a block of code at least once and then continues to execute
the block as long as a condition is true.
for
switch
Tests a variable against a series of case statements and executes a block of code
corresponding to the first matching case.
break
continue
Skips the current iteration of a loop and continues with the next iteration.
return
struct
Defines a composite data type that groups together variables of different types.
enum
#define
Defines a macro that can replace text in the source code with a predefined value
Terminology
Definition
Variable
A named location in memory that stores a value. Variables in C have a data type
that determines the type of data they can store.
Data Type
A classification of data that determines the size and type of operations that can be
performed on that data. C has several built-in data types, including integer,
floating-point, and character.
Function
A named block of code that performs a specific task. Functions can accept input
parameters and return a value to the calling code.
Pointer
A variable that stores the memory address of another variable. Pointers are a
powerful feature of C that allows for dynamic memory allocation and efficient
manipulation of data structures.
Array
A collection of variables of the same data type that are stored sequentially in
memory. Arrays can be used to store and manipulate large sets of data.
Struct
A composite data type that groups together variables of different types under a
single name. Structs are commonly used to represent complex data structures.
Operator
Loop
Condition
A logical expression that evaluates to either true or false. Conditions are used in
control structures, such as if statements and loops, to determine which code is
executed.
Control Structure
Header File
A file that contains declarations for functions, variables, and data types that are
used in a C program. Header files are typically included in a C source file using the
#include directive.
Preprocessor Directive
Compiler
A program that translates source code into machine code that a computer can
execute. C programs are typically compiled using a C compiler such as GCC or
Clang.
Linker
Library