C Programming – Fundamental Basics


1️⃣ Introduction to C Programming

C is a powerful, general-purpose, structured programming language developed in 1972 by at . It was mainly designed for system programming and for developing the operating system.

C is often called the “Mother of Programming Languages” because many modern programming languages like C++, Java, and C# are derived from or influenced by C.

Why Learn C?

  • Builds strong programming fundamentals
  • Improves understanding of memory management
  • Base for advanced languages
  • Widely used in embedded systems and OS development



2️⃣ Characteristics of C Language

1. Structured Language

C follows a structured programming approach. Programs are divided into functions and blocks.

2. Middle-Level Language

C supports both high-level features (like functions) and low-level features (like pointers and memory access).

3. Portable

Programs written in C can run on different machines with minimal changes.

4. Efficient and Fast

C is a compiled language, so it runs very fast compared to interpreted languages.

5. Rich Standard Library

C provides many built-in functions through libraries such as:

  • stdio.h
  • string.h
  • math.h
  • stdlib.h

3️⃣ Structure of a C Program

A C program generally contains the following sections:

  1. Documentation Section
  2. Link Section
  3. Definition Section
  4. Global Declaration Section
  5. main() Function
  6. User-defined Functions

Basic Structure Example:

#include <stdio.h>

int main() {
    printf("Hello World");
    return 0;
}

Explanation:

  • #include <stdio.h> → Includes standard input/output library
  • main() → Entry point of program
  • printf() → Displays output
  • return 0; → Indicates successful execution

Program execution always starts from the main() function.


4️⃣ Tokens in C

Tokens are the smallest individual units in a C program.

Types of Tokens:

  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Operators
  6. Special Symbols

Example:

int a = 10;
  • int → Keyword
  • a → Identifier
  • 10 → Constant
  • = → Operator

5️⃣ Keywords

Keywords are reserved words that have predefined meanings.

Examples:

  • int
  • float
  • char
  • if
  • else
  • for
  • while
  • switch
  • return
  • break
  • continue
  • struct
  • const

Keywords cannot be used as variable names.


6️⃣ Data Types in C

Data type defines the type of data a variable can store.

(A) Basic Data Types

Data Type Description
int Stores integers
float Stores decimal values
double Stores large decimal values
char Stores single character

(B) Derived Data Types

  • Array
  • Pointer
  • Function

(C) User-defined Data Types

  • struct
  • union
  • enum

Data types determine:

  • Memory size
  • Range of values
  • Type of operations allowed

7️⃣ Variables and Constants

Variable

A variable is a named memory location used to store data.

Rules for Naming Variables:

  • Must begin with letter or underscore
  • Cannot start with number
  • Cannot use keywords
  • Case-sensitive

Example:

int marks = 95;

Constant

A constant is a fixed value that does not change during program execution.

Example:

const float PI = 3.14;

Types of Constants:

  • Integer constant
  • Floating constant
  • Character constant
  • String constant

8️⃣ Operators in C

Operators are symbols used to perform operations.

1. Arithmetic Operator 

+-*/ %

2. Relational Operators

== != > < >= <=

3. Logical Operators

&& || !

4. Assignment Operator

=

5. Increment/Decrement

++ --

Operators are used to form expressions.


9️⃣ Input and Output

C uses standard input/output functions.

printf()

Used to display output.

printf("Hello");

scanf()

Used to take input.

int num;
scanf("%d", &num);

Format Specifiers:

  • %d → int
  • %f → float
  • %c → char
  • %s → string

The & symbol is used to provide the memory address of the variable.


🔟 Control Statements

Control statements control the flow of execution.

1. Decision Making Statements

if Statement

Executes block if condition is true.

if-else Statement

Provides two alternative blocks.

Nested if

Multiple conditions inside another if.

switch Statement

Used when multiple choices are available.


2. Looping Statements

Loops are used to execute a block repeatedly.

for Loop

Used when number of iterations is known.

while Loop

Executes as long as condition is true.

do-while Loop

Executes at least once.

Loops are important for repetitive tasks.


1️⃣1️⃣ Functions

A function is a block of code that performs a specific task.

Advantages:

  • Code reusability
  • Modularity
  • Easy debugging

Types:

  • Library Functions
  • User-defined Functions

Example:

int add(int a, int b) {
    return a + b;
}

Components:

  • Return type
  • Function name
  • Parameters
  • Function body
  • Return statement

1️⃣2️⃣ Arrays

An array is a collection of elements of the same data type.

Example:

int arr[5] = {1,2,3,4,5};

Features:

  • Fixed size
  • Index starts from 0
  • Stored in contiguous memory

Types:

  • One-dimensional array
  • Two-dimensional array

1️⃣3️⃣ Pointers

A pointer is a variable that stores the address of another variable.

Example:

int a = 10;
int *p = &a;
  • p → Address
  • *p → Value

Uses:

  • Dynamic memory allocation
  • Function call by reference
  • Data structures

Pointers are one of the most powerful features of C.


1️⃣4️⃣ Structure and Union

Structure

Used to group variables of different data types.

Example:

struct Student {
   int roll;
   char name[20];
};

Union

Similar to structure but shares memory among members.

Difference:

  • Structure allocates separate memory for each member
  • Union allocates shared memory

1️⃣5️⃣ Storage Classes

Storage classes define scope and lifetime of variables.

Types:

  • auto
  • static
  • extern
  • register

They control:

  • Visibility
  • Memory allocation
  • Lifetime

1️⃣6️⃣ Preprocessor Directives

Executed before compilation.

Examples:

  • #include
  • #define
  • #ifdef

Used for:

  • Including files
  • Defining macros
  • Conditional compilation

1️⃣7️⃣ Advantages of C

  • Fast execution
  • Direct memory access
  • Portable
  • Efficient
  • Strong foundation

1️⃣8️⃣ Limitations of C

  • No object-oriented support
  • No built-in garbage collection
  • Manual memory management

📌 Conclusion

C programming is one of the most important foundational languages in computer science. It provides strong control over hardware and memory, making it ideal for system programming and embedded systems.

Learning C helps in understanding core programming concepts such as loops, conditions, functions, arrays, pointers, and memory management. Once a learner masters C, it becomes easier to learn advanced programming languages.

C remains relevant even today due to its efficiency, portability, and deep-level control over system resources.



Comments

Popular Posts