Chapter 1: Introduction to C Language
1.1 Introduction
C is one of the most popular and important programming languages in computer science. It is a general-purpose programming language used to create software, operating systems, applications, embedded systems, and many other programs.
C language is known for its:
Simple syntax
Fast execution
High performance
Portability
Structured programming features
Ability to work closely with computer hardware
Learning C also helps students understand many important programming concepts such as variables, data types, operators, conditions, loops, functions, arrays, and pointers.
1.2 History of C Language
The C programming language was developed by Dennis Ritchie at Bell Laboratories in the early 1970s.
It was mainly developed for creating the UNIX operating system.
C became popular because it provided a good balance between:
High-level programming features – easy to write and understand
Low-level programming features – ability to interact closely with computer hardware
Today, C has influenced many modern programming languages, including:
C++
Java
C#
JavaScript
Python and many others
1.3 Features of C Language
1. Simple and Easy to Learn
C has a relatively simple structure and a small set of keywords. Beginners can start learning programming concepts using C.
2. Fast and Efficient
Programs written in C are generally fast because C allows efficient use of computer memory and system resources.
3. Portable
A C program can often be used on different computer systems with little or no modification.
4. Structured Programming
A large program can be divided into smaller parts called functions. This makes programs easier to understand and manage.
5. Rich Library Support
C provides many standard library functions that help programmers perform common tasks such as input, output, mathematical calculations, and string operations.
6. Foundation for Other Languages
Many programming concepts used in modern languages are based on ideas commonly taught through C programming.
1.4 Where is C Language Used?
C language is used in many areas of computing.
Some common applications include:
Operating systems
System software
Embedded systems
Device drivers
Compilers
Database systems
Networking applications
IoT devices
Game development components
1.5 Basic Structure of a C Program
Let us look at a simple C program.
#include <stdio.h> int main() { printf("Hello, World!"); return 0; }
When this program is executed, the output will be:
Hello, World!
1.6 Explanation of the Program
#include <stdio.h>
This line is called a preprocessor directive.
It includes the Standard Input Output library, which provides functions such as:
printf()
scanf()
The printf() function is used to display output on the screen.
int main()
The main() function is the starting point of a C program.
Program execution normally begins from the main() function.
int main() { // Program statements }
Curly Braces { }
Curly braces define the beginning and end of a block of code.
{ printf("Hello"); }
All statements belonging to a function are generally written inside curly braces.
printf()
The printf() function is used to display information on the screen.
Example:
printf("Welcome to C Programming");
Output:
Welcome to C Programming
return 0;
The statement:
return 0;
indicates that the main() function has completed successfully.
1.7 Keywords in C
Keywords are reserved words that have a special meaning in the C programming language.
Some common C keywords are:
| Keyword | Purpose |
|---|---|
| int | Used for integer values |
| float | Used for decimal values |
| char | Used for characters |
| if | Used for decision making |
| else | Used for an alternative condition |
| for | Used for looping |
| while | Used for looping |
| return | Returns a value from a function |
| void | Represents no value |
| break | Terminates a loop or switch |
Keywords cannot normally be used as variable names.
For example:
int age = 20;
Here, int is a keyword, while age is a variable.
1.8 Tokens in C
The smallest individual units in a C program are called tokens.
Common types of tokens include:
Keywords
Identifiers
Constants
Strings
Operators
Special symbols
Example:
int marks = 90;
This statement contains several tokens:
int → Keyword
marks → Identifier
= → Operator
90 → Constant
; → Special symbol
1.9 Identifiers
Identifiers are names given to program elements such as:
Variables
Functions
Arrays
Example:
int studentAge; float percentage;
Here:
studentAge
percentage
are identifiers.
Rules for Naming Identifiers
An identifier can contain letters, digits, and underscore _.
It should not begin with a digit.
Spaces are not allowed.
C keywords cannot be used as identifiers.
Identifiers are case-sensitive.
Example:
int age; int Age;
Both can be treated as different identifiers because C is case-sensitive.
1.10 Variables in C
A variable is a named memory location used to store data.
Example:
int age = 18;
In this example:
int represents the data type.
age is the variable name.
18 is the stored value.
Another example:
float marks = 85.5;
1.11 Data Types in C
A data type tells the compiler what type of information will be stored in a variable.
Some common data types are:
| Data Type | Used For | Example |
|---|---|---|
| int | Whole numbers | 25 |
| float | Decimal numbers | 12.5 |
| double | Large decimal values | 123.456 |
| char | Single characters | 'A' |
| void | No value | Functions |
Example:
int age = 20; float percentage = 85.5; char grade = 'A';
1.12 Taking Input from the User
The scanf() function is commonly used to accept input from the user.
Example:
#include <stdio.h> int main() { int age; printf("Enter your age: "); scanf("%d", &age); printf("Your age is %d", age); return 0; }
If the user enters:
18
The output will be:
Your age is 18
1.13 Comments in C
Comments are notes written inside a program to explain the code. Comments are generally ignored during program execution.
Single-Line Comment
// This is a single-line comment
Example:
// Display a welcome message printf("Welcome");
Multi-Line Comment
/* This is a multi-line comment */
Comments make programs easier to understand and maintain.
1.14 Semicolon in C
Most C statements end with a semicolon ;.
Example:
int number = 10; printf("Hello");
A missing semicolon may cause a compilation error.
1.15 C is Case-Sensitive
C programming language is case-sensitive.
For example:
int age = 20;
The following names are different:
age Age AGE
Similarly:
printf()
and
PRINTF()
are not the same.
1.16 A Simple Addition Program
#include <stdio.h> int main() { int a = 10; int b = 20; int sum; sum = a + b; printf("Sum = %d", sum); return 0; }
Output
Sum = 30
1.17 Important Points to Remember
C is a general-purpose programming language.
C programs are made up of functions and statements.
Program execution starts from the main() function.
printf() is used to display output.
scanf() is used to take input.
Variables are used to store data.
Every variable has a data type.
C is a case-sensitive language.
Most statements end with a semicolon ;.
Comments are used to explain program code.
Chapter Summary
In this chapter, you learned the basic concepts of the C Programming Language. You learned about the history and features of C, its applications, the structure of a basic C program, keywords, tokens, identifiers, variables, data types, input and output functions, comments, and simple C programs.
These concepts form the foundation for learning advanced topics such as operators, decision-making statements, loops, arrays, functions, pointers, structures, and file handling.
Practice Questions
Very Short Answer Questions
What is C language?
Who developed the C programming language?
What is the purpose of the main() function?
Which function is used to display output in C?
Which function is commonly used to take input?
What is a variable?
What are keywords?
Is C a case-sensitive language?
Short Answer Questions
Explain any four features of C language.
Explain the basic structure of a C program.
What are identifiers? Write the rules for naming identifiers.
Explain different basic data types in C.
Differentiate between printf() and scanf().
What are comments? Explain their types.
Programming Questions
1. Write a program to display your name.
#include <stdio.h> int main() { printf("My Name is Rahul"); return 0; }
2. Write a program to add two numbers.
#include <stdio.h> int main() { int a, b, sum; a = 15; b = 25; sum = a + b; printf("Sum = %d", sum); return 0; }
3. Write a program to display student information.
#include <stdio.h> int main() { printf("Name: Rahul\n"); printf("Class: 10\n"); printf("Subject: Computer Science"); return 0; }
This tutorial is originally written content that you can adapt and publish on your website GWALNET.