0% found this document useful (0 votes)
4 views7 pages

Detailed C Language Notes

This document provides an introduction to the C programming language, covering its history, features, structure of a C program, and key components such as functions, operators, and data types. It also discusses control structures, including decision-making and iteration statements, as well as arrays and their usage in C. Mastery of C is emphasized as foundational for learning other programming languages.

Uploaded by

32pygowczx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Detailed C Language Notes

This document provides an introduction to the C programming language, covering its history, features, structure of a C program, and key components such as functions, operators, and data types. It also discusses control structures, including decision-making and iteration statements, as well as arrays and their usage in C. Mastery of C is emphasized as foundational for learning other programming languages.

Uploaded by

32pygowczx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

🧩 UNIT – I : Introduction to ‘C’ Language

------------------------------------------------------------
1. LANGUAGE FUNDAMENTALS
------------------------------------------------------------

HISTORY OF C LANGUAGE
- Developed by **Dennis Ritchie** in **1972** at **AT&T Bell Laboratories, USA**.
- Evolved from **B and BCPL languages**.
- Originally designed for writing **UNIX Operating System**.
- C became popular due to its **portability**, **efficiency**, and **powerful
features**.
- It influenced many languages such as **C++, Java, C#, and Python**.

📘 FEATURES OF C
1. Simple and powerful language.
2. Portable and machine independent.
3. Supports structured programming.
4. Has rich set of operators and data types.
5. Allows low-level memory access (using pointers).
6. Supports modular and function-based design.

------------------------------------------------------------
STRUCTURE OF A C PROGRAM
------------------------------------------------------------

A basic C program looks like this:

```c
#include <stdio.h> // Header File
#define PI 3.14 // Macro Definition

void main() // Main Function


{
int radius;
float area;

printf("Enter radius: ");


scanf("%d", &radius);

area = PI * radius * radius;


printf("Area = %f", area);
}
```

🧩 MAIN COMPONENTS
1. **Documentation Section** – Comments about the program.
2. **Link Section** – Includes header files.
3. **Definition Section** – Defines constants/macros.
4. **Global Declaration Section** – Declares global variables.
5. **Main Function Section** – The starting point of every program.
6. **User-Defined Functions** – Reusable code blocks.

------------------------------------------------------------
🧱 FUNCTION AS BUILDING BLOCKS
------------------------------------------------------------
- Functions divide the program into small manageable parts.
- **Advantages:**
- Reusability
- Easier testing & debugging
- Better readability
- Example:
```c
int add(int a, int b)
{
return a + b;
}
void main()
{
int result = add(5, 10);
printf("Sum = %d", result);
}
```

------------------------------------------------------------
🔠 CHARACTER SET AND TOKENS
------------------------------------------------------------
- Alphabets: A–Z, a–z
- Digits: 0–9
- Special Symbols: +, -, *, /, %, =, #, &, <, >, etc.
- White Spaces: space, tab, newline

💡 TOKENS IN C
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Operators
6. Special Symbols

------------------------------------------------------------
🔑 KEYWORDS
------------------------------------------------------------
- Predefined reserved words that have specific meaning.
- Examples: int, float, char, if, else, for, while, return, switch, break, void
- There are **32 keywords** in standard C.

------------------------------------------------------------
🧩 IDENTIFIERS & VARIABLES
------------------------------------------------------------
Identifiers:
- Names given to variables, functions, or arrays.
- Rules:
- Must begin with a letter or underscore (_).
- Case-sensitive.
- Cannot use C keywords.

Variables:
- Named memory locations to store data.
- Example:
```c
int age = 21;
float salary = 25000.75;
char grade = 'A';
```

------------------------------------------------------------
🔢 CONSTANTS AND DATA TYPES
------------------------------------------------------------
Constants:
- Fixed values that don’t change during execution.
Types:
1. Integer constants → 10, -20
2. Floating constants → 3.14, -2.5
3. Character constants → 'A', '7'
4. String constants → "Hello"

Data Types:
| Type | Size | Example |
|------|------|----------|
| int | 2 or 4 bytes | 10 |
| float | 4 bytes | 3.14 |
| char | 1 byte | 'A' |
| double | 8 bytes | 45.67 |
| void | — | no value |

------------------------------------------------------------
💬 COMMENTS
------------------------------------------------------------
Used to make programs readable.
```c
// Single line comment
/* Multi-line
comment */
```

------------------------------------------------------------
2. OPERATORS
------------------------------------------------------------

🧮 TYPES OF OPERATORS
1. Arithmetic → +, -, *, /, %
2. Relational → <, >, <=, >=, ==, !=
3. Logical → &&, ||, !
4. Assignment → =, +=, -=, *=, /=, %=
5. Increment/Decrement → ++, --
6. Conditional → ?:
7. Bitwise → &, |, ^, ~, <<, >>
8. Special → sizeof(), &, *

Example:
```c
int a=5, b=2;
int c = a + b * 3; // precedence of * over +
```

📈 PRECEDENCE & ASSOCIATIVITY


- Determines order of execution of operators.
- Multiplication/division have higher precedence than addition/subtraction.
- Associativity: Left to Right (mostly).

------------------------------------------------------------
3. INPUT/OUTPUT FUNCTIONS
------------------------------------------------------------

📥 INPUT & OUTPUT


- Console-based I/O means using screen & keyboard.
Functions:
| Function | Purpose | Example |
|-----------|----------|----------|
| printf() | Output to screen | printf("Hello"); |
| scanf() | Input from user | scanf("%d", &num); |
| getch() | Waits for key press | getch(); |
| getche() | Key press + echo | getche(); |
| putchar() | Prints single character | putchar('A'); |

Example:
```c
int a;
printf("Enter number: ");
scanf("%d", &a);
printf("You entered %d", a);
```

------------------------------------------------------------
4. HEADER FILES & PREPROCESSOR DIRECTIVES
------------------------------------------------------------

📂 HEADER FILES
- Contain predefined functions and macros.
- Common headers:
- stdio.h → Input/Output
- math.h → Math functions
- string.h → String operations

⚙️ PREPROCESSOR DIRECTIVES
- Commands executed before actual compilation.
```c
#include <stdio.h> // Adds header file
#define PI 3.14 // Defines constant
```

------------------------------------------------------------
⚙️ UNIT – II : CONTROL STRUCTURES
------------------------------------------------------------

1. DECISION-MAKING STATEMENTS

🧠 if Statement
```c
if(a > b)
printf("A is greater");
```

🧩 if-else
```c
if(a > b)
printf("A");
else
printf("B");
```

🧱 Nested if-else
```c
if(a > 0)
{
if(a % 2 == 0)
printf("Positive Even");
else
printf("Positive Odd");
}
```

🔀 switch Statement
```c
switch(choice)
{
case 1: printf("Add"); break;
case 2: printf("Subtract"); break;
default: printf("Invalid");
}
```

------------------------------------------------------------
2. ITERATION (LOOPING) STATEMENTS
------------------------------------------------------------

🔁 while Loop
```c
int i=1;
while(i<=5)
{
printf("%d ", i);
i++;
}
```

🔂 do-while Loop
```c
int i=1;
do
{
printf("%d ", i);
i++;
}while(i<=5);
```

🔁 for Loop
```c
for(i=1; i<=5; i++)
printf("%d ", i);
```

------------------------------------------------------------
3. JUMPING STATEMENTS
------------------------------------------------------------

➡️ goto Statement
```c
goto label;
printf("Skip");
label: printf("Here");
```
🔚 return Statement
- Used to return value from a function.
```c
return 0;
```

🛑 break Statement
- Exits loop or switch immediately.

↪️ continue Statement
- Skips remaining code of current loop iteration.

------------------------------------------------------------
4. ARRAYS IN C
------------------------------------------------------------

📘 Definition
Array is a collection of **same type elements** stored in continuous memory.

🧩 Declaration
```c
int marks[5];
```

🧮 Initialization
```c
int marks[5] = {90, 80, 70, 60, 50};
```

📊 Types of Arrays
1. **Single Dimensional**
```c
int arr[5] = {1,2,3,4,5};
```
2. **Multi Dimensional**
```c
int matrix[2][3] = {{1,2,3}, {4,5,6}};
```

💡 Example Program
```c
#include <stdio.h>
void main()
{
int marks[5] = {78, 89, 90, 85, 70};
int i;
for(i=0; i<5; i++)
printf("Marks[%d] = %d
", i, marks[i]);
}
```

------------------------------------------------------------
📘 CONCLUSION
------------------------------------------------------------
- C language is the foundation of programming.
- Mastering its syntax, logic, and structure helps in learning other languages.
- Understanding control structures, arrays, and operators is essential for logical
problem-solving.
------------------------------------------------------------
END OF UNIT I & II NOTES
------------------------------------------------------------

You might also like