Lecture 2 c progamming.pdf.. helpful for beginners
jenajijnasha
10 views
39 slides
Sep 16, 2025
Slide 1 of 39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
About This Presentation
This PDF lecture material has been specially designed as a complete beginner’s guide to learning the C programming language. It introduces the subject in a simple, clear, and well-structured way so that students with little or no prior programming background can start their journey in computer sci...
This PDF lecture material has been specially designed as a complete beginner’s guide to learning the C programming language. It introduces the subject in a simple, clear, and well-structured way so that students with little or no prior programming background can start their journey in computer science with confidence. The purpose of this material is to make programming accessible, understandable, and engaging by focusing on the core foundations of C, one of the most widely used and time-tested programming languages in the world.
C programming is often called the “mother of all programming languages” because many modern languages such as C++, Java, and Python have their roots in it. It is powerful, efficient, and close to the hardware, making it a perfect starting point for understanding how computers work internally. This PDF provides a beginner-friendly overview of C, ensuring that learners not only write code but also develop logical thinking and problem-solving skills.
The content starts with the very basics—introduction to programming, the history of C, features of the language, and setting up the environment for compiling and running programs. From there, it gradually moves toward fundamental concepts such as data types, variables, constants, operators, and expressions. These form the building blocks of every C program, and the PDF explains them with examples that are easy to follow.
Control structures like decision-making (if, if-else, switch) and looping (for, while, do-while) are explained in detail so that students can understand how to control the flow of their program logically. The material also covers input and output functions, enabling learners to interact with users by reading values and displaying results. Each concept is presented with sample programs, step-by-step explanations, and practice exercises to encourage hands-on learning.
As the material progresses, it introduces more advanced but essential topics such as arrays, strings, functions, pointers, and structures. Arrays and strings teach how to handle collections of data efficiently, while functions help in breaking down big problems into smaller modules. Pointers, one of the most powerful features of C, are explained with diagrams and examples so that beginners can overcome fear and gain clarity. Structures are introduced to help students understand how to organize complex data in real-world applications.
Memory management, file handling, and an overview of dynamic data structures are also included to give learners a complete beginner-level picture of what C can do. The focus is not only on syntax but also on developing an analytical approach to solving problems. Every topic is explained with clear definitions, examples, and illustrations, making it easy for students to grasp the concepts even if they are encountering programming for the first time.
By going through this PDF, students will:
Gain a solid foundation in the fundamentals of programming.
Size: 3.07 MB
Language: en
Added: Sep 16, 2025
Slides: 39 pages
Slide Content
C
PROGRAMMING
1.Importance Of C
2.Constants And Variables
Importance Of C
•It is one of the most popular
programming languages in the world.
•C is a robust language whose rich set of
built-in functions and operators can be
used to write any complex
program.
•C language is efficient and fast.
•C language is well suited for
structured programming.
Add a footer 3
FR
•C is very versatile. It can be used in
both applications and technologies.
•Most of libraries of today’s operating
system are written in c language.
•There are only 32 keywords in C and
its strength lies in its built-in functions.
•C is highly portable i.e the programs
written for one computer can be run
on another computer easily.
•Ability to extends itself i.e we can
add our own function to c library.
Add a footer 4
FR
Add a footer 5
FR
CONSTANTS AND VARIABLES
CONSTANTS
A constant is a value or variable in c
programming which cannot be changed
once they are defined in the program.
There can be any types of constants like
integer,float,hexadecimal,character
constants etc.
Now there are various ranges that differ
from unsigned to signed bits.Under the
signed bit,the range of an int varies from -
128 to +127 and under the unsigned
bit,int varies from 0 to 255.
Add a footer 6
FR
Add a footer 7
EXAMPLE
FR
Add a footer 8
OUTPUT
FR
Add a footer 9
VARIABLES
•A variable is a name of the memory location. It is used to
store data. Its value can be changed and it can be reused
many times.
•Different types of variables require different amounts of
memory and have some specific set of operations which can
be applied to them.
•Rules for Defining Variables
•A variable can have alphabets, digits and underscore.
•A variable name can start with the alphabet and underscore
only. It can’t start with a digit.
•It should not contain white spaces.
•A variable name should not be a reserved word or keyword.
FR
Add a footer 10
Syntax
•type variableName = value;
•where type is one of C types(such as int)and variableName is the name of
the variable(such as x or myName).The equal sign is used to assign a value
to the variable.
•EXAMPLE
•int myNum = 15;
FR
Add a footer 11
EXAMPLE
FR
Add a footer 12
OUTPUT
FR
Add a footer 13
FR
Add a footer 14
VARIABLE DECLARATION
•type variable_name;
•For Example,
•int a,b;
•float c;
•double d;
•Here a,b,c,d are variables.The int,float,double are data tpes.
VARIABLE ASSIGNMENT
•A variable assignment is a process of assigning a value to a variable.
•For Example
•int height = 40;
•Int base = 31;
FR
CONSTANTS VS VARIABLES
CONSTANTS
It is similar to a variable and cannot be
changed during Program execution.
It is a fixed variable that cannot be
changed after defining the variable in
a program.
In constants, the value cannot be
changed.
It can be express in two ways:#define
pre-processor and the const keyword.
Example: const int Len=5;
#define PI 3.14
VARIABLES
It is a variable that stores data type value
in a program
It is a variable that can be changed after
defining the variable in a program.
The value of a variable can change
depending on the conditions.
Typically it uses int,foat,string,double,etc
data types in a program.
Example: int a=5;float radius=5.2;char ‘A’;
Add a footer 15
FR
Add a footer 16
FR
Add a footer 17
SYMBOLIC CONSTANTS
•A symbolic constant is a name given to a some numeric constant or a
character constant or string constant,or any other constants.
•Symbolic constant names are also known as constant identifiers.Pre-
processor directive #define is used for defining symbolic constants.
SYNTAX
#define PI 3.141592
#define GOLDENRATIO 1.6
#define MAX 500
Here PI,GOLDENRATIO,SIZE are symbolic constants.
When we attempt to store a value
that cannot be represented correctly
by a data type,an Integer Overflow
(or) Underflow occurs.If the value is
more than the maximum
representable value, the phenomenon
is called Integer Overflow. The
phenomenon is called Integer
Underflow if the value is less than the
least representable value of the
datatype.
OVERFLOW AND UNDERFLOW
Add a footer 18
FR EXAMPLE OF OVERFLOW
Add a footer 19
OUTPUT
Add a footer 20
FR
EXAMPLE OF UNDERFLOW
Add a footer 21
OUTPUT
Add a footer 22
FR
Add a footer 23
FR
Add a footer 24
ARRAYS IN C
•An array is defined as the collection of similar type of
data items stored at contiguous memory locations.
Arrays are the derived data type in C programming
language which can store the primitive type of data such
as int, char, double, float, etc. It also has the capability
to store the collection of derived data types, such as
pointers, structure, etc. The array is the simplest data
structure where each data element can be randomly
accessed by using its index number.
•Each element of an array is of same data type and
carries the same size, i.e., int = 4 bytes.
•Elements of the array are stored at contiguous
memory locations where the first element is stored at
the smallest memory location.
•Elements of the array can be randomly accessed
since we can calculate the address of each element
of the array with the given base address and the
size of the data element.
PROPERTIES
OF ARRAYS
Add a footer 25
Why do we need arrays?
We can use normal variables (v1, v2, v3,..) when
we have a small number of objects, but if we
want to store a large number of instances, it
becomes difficult to manage them with normal
variables. The idea of an array is to represent
many instances in one variable.
FR
ADVANTAGE OF ARRAY IN C
Add a footer 28
1) Code Optimization: Less code to the access the data.
2) Ease of traversing: By using the for loop, we can retrieve the
elements of an array easily.
3) Ease of sorting: To sort the elements of the array, we need a
few lines of code only.
4) Random Access: We can access any element randomly using the
array.
DISADVANTAGE OF ARRAY IN C
1) Fixed Size: Whatever size, we define at the time of
declaration of the array, we can't exceed the limit. So, it
doesn't grow the size dynamically like LinkedList which we
will learn later.
One Dimensional Arrays
We can visualize a one -dimensional
array in C as a single row to store the
elements. All the elements are stored at
contiguous memory locations. Now, we
will see how to declare, initialize and
access array elements:
You can declare an array of any data type (i.e. int,
float, double, char) in C.
Array Declaration
While declaring a one-dimensional array in
C, the data type can be of any type, and
also, we can give any name to the array, just
like naming a random variable.
Syntax:
int arr[5]; //arr is the array name of type integer, and 5 is the size of the array
Array Initialization
In static uninitialized arrays, all the elements
initially contain garbage values, but we can
explicitly initialize them at their declaration.
SYNTAX:
<data_type> <arr_name> [arr_size]={value1, value2, value3,…};
FR
Add a footer 31
Array Accessing
In one-dimensional arrays in C, elements are accessed by specifying the
array name and the index value within the square brackets. Array
indexing starts from 0 and ends with size-1. If we try to access array
elements out of the range, the compiler will not show any error message;
rather, it will return some garbage value.
Syntax:
<arr_name>[index];
FR
Add a footer 33
EXAMPLE
#include < stdio.h >
int main() {
//declaring and initializing one -dimensional array in C
int arr[3] = {10, 20, 30};
// After declaration, we can also initialize the array as:
// arr[0] = 10; arr[1] = 20; arr[2] = 30;
for (int i = 0; i < 3; i++) {
// accessing elements of array
printf(" Value of arr[%d]: %d\n", i, arr[i]);
}
}
OUTPUT
Value of arr[0]: 10
Value of arr[1]: 20
Value of arr[2]: 30
FR
Add a footer 35
TWO-DIMENSIONAL ARRAYS
The two-dimensional array can be defined as an array of arrays. The 2D
array is organized as matrices which can be represented as the collection of
rows and columns. However, 2D arrays are created to implement a
relational database lookalike data structure. It provides ease of holding the
bulk of data at once which can be passed to any number of functions
wherever required.
FR
Add a footer 36
Declaration of two dimensional Array in C
The syntax to declare the 2D array is given below.
data_type array_name[rows][columns];
Consider the following example.
int twodimen[4][3];
Here, 4 is the number of rows, and 3 is the number of columns.
Initialization of 2D Array in C
The two-dimensional array can be initialized and defined in the following way.
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};