C Language Short Note
C Language Short Note
C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories as an enhancement to
the B programming language. It was initially designed to write the Unix operating system and
has since evolved into one of the most widely used programming languages for systems
programming, embedded systems, and software development.
Structure of C Programming:
Functions: Functions are the main components. Each program must have a main()
function, which is the entry point.
Variables: To store data.
Statements and expressions: These are instructions to perform specific operations.
Control structures: Such as loops (for, while, do-while) and conditional statements
(if, switch).
Preprocessor directives: Statements that are processed before compilation, such as
#include and #define.
Functions in C are blocks of code designed to perform a specific task. Every C program has a
main() function, and additional functions can be created to improve modularity and reusability.
Functions can take parameters and return values, allowing for flexibility in how data is
processed.
Language Fundamentals
1. Character Set: C supports a standard character set that includes letters (both uppercase
and lowercase), digits (0-9), special characters (e.g., !, @, #), and whitespace (spaces,
tabs, newlines).
2. C Tokens: The smallest individual units in a C program are called tokens. These include:
o Keywords: Reserved words like int, return, if, else, etc.
o Identifiers: User-defined names for variables, functions, etc.
o Constants: Fixed values such as 42, 3.14, 'A', "Hello".
o Operators: Symbols that specify operations (e.g., +, -, *, =, etc.).
o Separators: Symbols like ; (semicolon) and , (comma).
3. Keywords: Reserved words with predefined meaning. Some important keywords include
int, char, if, for, while, void, return, etc.
4. Identifiers: These are the names used to identify variables, functions, arrays, etc. An
identifier must start with a letter or an underscore and can consist of letters, digits, and
underscores.
5. Variables: These are names given to memory locations used to store data. Each variable
must be declared with a data type (e.g., int a;, float b;).
6. Constants: Fixed values that do not change during the execution of a program. Examples
include integer constants, floating-point constants, character constants, and string
constants.
7. Data Types:
o Basic types: int, char, float, double.
o Derived types: Arrays, pointers, structures, unions.
o Void type: Used for functions that return no value.
8. Comments:
o Single-line comments: Written using //.
o Multi-line comments: Written between /* */.
Operators
1. Types of Operators:
o Arithmetic Operators: +, -, *, /, %.
o Relational Operators: ==, !=, >, <, >=, <=.
o Logical Operators: &&, ||, !.
o Bitwise Operators: &, |, ^, ~, <<, >>.
o Assignment Operators: =, +=, -=, *=, /=, %=.
o Increment/Decrement Operators: ++, --.
2. Precedence and Associativity:
o Operators have a specific precedence (priority) that dictates the order in which
operations are performed. For example, * has a higher precedence than +.
o Associativity defines the direction of operation if operators have the same
precedence. Most operators have left-to-right associativity, but assignment
operators are right-to-left.
3. Expression: An expression is a combination of operators and operands that compute a
value. For example, a + b is an expression.
4. Statement and Types of Statements:
o Expression Statement: A statement that evaluates an expression (e.g., a = b +
c;).
o Conditional Statement: if, else, switch.
o Iteration Statements: for, while, do-while.
o Jump Statements: return, break, continue, goto.
Header files contain function prototypes and macros that are included in programs using the
#include directive. Commonly used header files are:
Preprocessor Directives
1. #include: Used to include standard or user-defined header files into the program. For
example: