0% found this document useful (0 votes)
6 views6 pages

Introduction to C Programming Basics

The document provides an introduction to the C programming language, detailing its features, structure, and basic components such as data types, operators, and input/output functions. It includes examples of C code, diagrams illustrating program structure, and explanations of tokens, constants, and variables. Additionally, it covers type conversion and mathematical functions available in C.

Uploaded by

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

Introduction to C Programming Basics

The document provides an introduction to the C programming language, detailing its features, structure, and basic components such as data types, operators, and input/output functions. It includes examples of C code, diagrams illustrating program structure, and explanations of tokens, constants, and variables. Additionally, it covers type conversion and mathematical functions available in C.

Uploaded by

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

UNIT – I: INTRODUCTION TO C

(10-mark type descriptive answers with diagrams and coding examples)

Introduction to C

C is a general-purpose, structured programming language developed by Dennis Ritchie in 1972


at Bell Labs.
It is widely used for system software, operating systems, and embedded systems.

Features of C

• Simple and efficient

• Portable (machine-independent)

• Structured programming

• Rich library functions

• Low-level (bitwise & pointer) manipulation

• Fast execution

Structure of a C Program

#include <stdio.h>

int main() {

printf("Hello, World!");

return 0;

Diagram: Structure of a C Program

+---------------------------------+

| Preprocessor directives |

| (e.g., #include <stdio.h>) |

+---------------------------------+

| Global declarations |
+---------------------------------+

| main() function |

|{ |

| local declarations; |

| statements; |

|} |

+---------------------------------+

Character Set, Tokens & Identifiers

Character Set – Letters, digits, special symbols, and white spaces used in a program.
Example: A-Z, a-z, 0-9, _, +, -, ;, etc.

Tokens in C

A token is the smallest unit in a C program.


Types of tokens:

1. Keywords (e.g., int, while)

2. Identifiers (user-defined names)

3. Constants (fixed values)

4. Strings ("Hello")

5. Operators (+, -, *, /)

6. Special symbols (;, {}, [], ())

Example

int total = a + b;

Tokens → int, total, =, a, +, b, ;

Constants and Variables

Constants are fixed values that do not change during program execution.
Variables are named memory locations used to store data.
Example:

#define PI 3.14159 // symbolic constant

int radius = 5;

float area = PI * radius * radius;

Diagram: Memory Representation

+------------+---------+

| Variable | Value |

+------------+---------+

| radius | 5 |

| area | 78.54 |

+------------+---------+

Data Types

C provides several basic data types.

Type Size (bytes) Example

int 2 or 4 10

float 4 12.45

double 8 125.678

char 1 'A'

Operators and Expressions

Operators are symbols that perform operations on operands.


Type Examples

Arithmetic +, -, *, /, %

Relational <, >, <=, >=, ==, !=

Logical &&,

Assignment =, +=, -=, *=, /=

Increment/Decrement ++, --

Bitwise &,

Example:

int a = 5, b = 3, c;

c = a + b * 2; // Expression

Operator Precedence Diagram

Highest → () → ++, -- → *, /, % → +, - → <, >, == → &&, || → =

Input and Output Functions

C uses stdio.h library functions for input and output.

Example:

#include <stdio.h>

int main() {

int a, b, sum;

printf("Enter two numbers: ");

scanf("%d%d", &a, &b);

sum = a + b;

printf("Sum = %d", sum);

return 0;

}
Output:

Enter two numbers: 10 20

Sum = 30

Type Conversion

Implicit Conversion (Type Promotion):


C automatically converts data types in expressions.
Example:
int a = 5; float b = 2.5; float c = a + b;

Explicit Conversion (Type Casting):


User specifies conversion manually.

float result = (float)5 / 2; // result = 2.5

Mathematical Functions

C provides math functions in <math.h>.

Function Description Example

sqrt(x) Square root sqrt(16) → 4

pow(x,y) x raised to y pow(2,3) → 8

abs(x) Absolute value abs(-5) → 5

sin(x), cos(x), tan(x) Trigonometric sin(0) → 0

Example:

#include <stdio.h>

#include <math.h>

int main() {

double n = 9.0;
printf("Square root = %.2f", sqrt(n));

return 0;

You might also like