C Language
Introduction
Introduction to C Language
Developed by: Dennis Ritchie in the early 1970s
Purpose: General-purpose programming language
Key Uses: System software, embedded systems, and application software
Preprocessor Directives: Instructions
processed before compilation, e.g., #include
<stdio.h>
Structure of a
Main Function: Entry point of every C
program, e.g., int main() { }
C Program Variable Declarations: Define variables to
store data
Components: Statements & Expressions: Execute the
program's logic
Comments: Annotate code for better
understanding, e.g., // This is a comment
variable Components:
⚬ A variable in C is a name given to a memory location where
declaration
data is stored. It can hold different values during the
execution of a program.
⚬ Syntax of Variable Declaration.
datatype variable_name;
⚬ datatype: Specifies the type of data the variable will store
(e.g., int, float, char).
⚬ variable_name: The name of the variable (identifier).
Variables
Rules:
⚬ Variables are case sensitive
⚬ 1st character is alphabet or '_'
⚬ no comma/blank space
⚬ No other symbol other than '_'
Compilation
and Execution
Compilation Steps:
Execution: Run the compiled
program on the system
1. Preprocessing: Handles directives like #include and
#define
2. Compilation: Translates C code into assembly code
3. Assembly: Converts assembly code into machine
code
4. Linking: Combines object files and libraries into an
executable
structure
Identifiers and Constants
Identifiers: Constants:
Names for variables, functions, arrays, etc. Fixed values that do not change
Must begin with a letter or underscore, followed by letters, Types include integer, floating-point, character, and string
digits, or underscores constants
Features of C Language
1 Portability: Code can run on different machines with minimal change
2 Efficiency: Provides low-level access to memory
3 Modularity: Supports functions for code reuse
4 Rich Library: Extensive set of built-in functions
5 Structured Language: Encourages clear and logical code structure
Keywords in C
• Definition: Reserved words with special meaning in C
• Examples:
⚬ Data types: int, char, float
⚬ Control flow: if, else, switch, for, while
⚬ Others: return, void, const, static
Keywords
in C
Preprocessors
• Role: Directives that provide instructions to the compiler
• Common Preprocessor Directives:
⚬ #define: Define macros
⚬ #include: Include header files
⚬ #ifdef, #ifndef: Conditional compilation
• Purpose: Enhance code readability and maintainability