1. Basics of C Programming
Basic Structure of C Program
A C program consists of header files, main function, variable declarations, and statements. Execution starts from the main() function.
Compilation and Execution of C Program
The source code is compiled using a compiler like GCC, which converts it into machine code, then executed to produce output.
Elements of C Program
- Keywords
- Identifiers
- Constants
- Variables
- Operators
- Statements
Escape Sequences
Escape sequences are special characters used in strings like \n (new line), \t (tab), \" (double quote).
Delimiters
Delimiters are symbols used to separate program elements such as semicolon (;), braces {}, and commas (,).
Keywords
Keywords are reserved words with predefined meaning such as int, float, if, else, return.
Identifiers
Identifiers are names given to variables, functions, or arrays. They must start with a letter or underscore.
Data Types
Data types specify the type of data a variable can store such as int, float, char, double.
Constants
Constants are fixed values that do not change during program execution.
Variables
Variables are named memory locations used to store data.
Expressions
An expression is a combination of operands and operators that evaluates to a value.
Statements
Statements are instructions given to the compiler to perform an action.
Expression Statements
Expression statements evaluate an expression such as assignment or function call.
Comments
Comments are used to explain code and are ignored by the compiler. They can be single-line or multi-line.
2. Operators and Expressions
Arithmetic Operators
Used for mathematical operations like +, -, *, /, and %.
Assignment Operators
Used to assign values to variables such as =, +=, -=.
Increment and Decrement Operators
Used to increase or decrease a value by one (++ and --).
Relational Operators
Used to compare two values like <, >, <=, >=, ==, !=
Logical Operators
Used to combine conditions such as &&, ||, !
Conditional (Ternary) Operator
A shorthand for if-else condition using ?: operator.
Sizeof Operator
Returns the size of a data type or variable in bytes.
Comma Operator
Allows multiple expressions to be evaluated sequentially.
Bitwise Operators
Operate on binary bits like &, |, ^, ~, <<, >>.
Type Conversion
Converts one data type to another automatically or manually.
Operator Precedence and Associativity
Defines the order in which operators are evaluated in an expression.
3. Control Statements
If-Else
Executes code based on a condition.
Nested If-Else
If-else statements inside another if-else.
Else If Ladder
Used to check multiple conditions sequentially.
For Loop
Used when the number of iterations is known.
While Loop
Repeats execution while a condition is true.
Do-While Loop
Executes code at least once before checking condition.
Nested Loops
A loop inside another loop.
Break
Terminates the loop or switch statement.
Continue
Skips the current iteration of a loop.
Goto
Transfers control to a labeled statement.
Switch Statement
Used to execute one case from multiple options.
4. Functions
Function with Parameters
Functions that accept input values.
No Arguments No Return Value
Function that neither takes input nor returns output.
Arguments with Return Value
Function that accepts input and returns a value.
No Argument with Return Value
Function that returns a value without taking input.
Local Variable
Declared inside a function and accessible only within it.
Global Variable
Declared outside functions and accessible throughout the program.
Static Variable
Preserves its value between function calls.
Call by Value and Call by Reference
Call by value passes copy, call by reference passes address.
5. Recursion
Recursion is a process where a function calls itself until a base condition is met.
6. Arrays
Types of Arrays
Arrays can be single, multi-dimensional, or dynamic.
Single Dimensional Array
Stores elements in a linear format.
Two Dimensional Array
Stores data in rows and columns.
Three Dimensional Array
Used to store data in 3D format.
Dynamic Array
Memory allocated at runtime using malloc or calloc.
Pointer Array
Array of pointers.
Constant Array
Array whose values cannot be modified.
7. Pointers
Pointer Basics
Pointers store memory addresses of variables.
Pointer Arithmetic
Used to navigate memory locations.
Pointers and Arrays
Array name acts as a pointer to the first element.
Function Pointers
Pointers that store function addresses.
Void Pointer
Generic pointer that can store address of any type.
8. Strings
String Handling
Strings are arrays of characters terminated by null character.
String Functions
- strlen()
- strcat()
- strcpy()
- strcmp()
- strchr()
9. Structures and Unions
Structure
Used to group different data types.
Union
Stores different data types in same memory location.
Typedef
Creates alias for data types.
12. File Handling
File Operations
Used to store data permanently using files.
File Modes
Common modes are r, w, a, a+.
Command Line Arguments
Used to pass arguments during program execution.
13. Featured Concepts
Preprocessor
Handles macros and header files.
Enum
Used to define named constants.
Const and Volatile
Const prevents modification, volatile prevents optimization.
Scope and Storage Class
Defines visibility and lifetime of variables.
Stack and Queue
Linear data structures used for data storage.
Codecrown