You are on page 1of 18

C LANGUAGE FOR

BEGINNERS
BY SHWETA KARKI
B.SC(H) MATHEMATICS.
GENERAL ASPECTS AND HISTORY OF C LANGUAGE

C language is a base for all the programming languages and since it's a mid level language it contains
both the features of a high level language and a low level language means, you can do both system based
programming and application based programing through it.

C is also a strategically typed language which means its data types cannot be changed during the runtime
of the code. C is also a structured programming language which means it uses a set of function and
modules.

C language was invented by Dennis Ritchie at bell laboratories in the early 1970’s. many of the ideas of c
language were taken from the earlier B language and its ancestors
BASIC C PROGRAM STRUCTURE AND HEADER FILES IN C

A c file ends with a .c extension and a mandatory ‘int main()’ function is required in every c file. On
top of your c file you can import other c files whose code can be used in your C file these type of
files are called header files and they end with a .h extension eg ‘filename.h’
To import a header file we use #include<filename.h> if its from the standard c library. Or in double
quotes if you have your own header file.
An example of a header file from c library is #include<stdio.h> which includes functions like
scanf() and printf() which are used for input and output in c.
BASIC C PROGRAM STRUCTURE AND HEADER FILES IN C
KEYWORDS AND DATATYPES IN C LANGUAGE

There are 32 keywords in C language and 5 primary data types. here are the five primitive or primary data
types that one can find in C programming language:
1. Integer – We use these for storing various whole numbers, such as 5, 8, 67, 2390, etc
2. Character – It refers to all character sets as well as the single alphabets, such as ‘x’, ‘Y’, etc.
3. Double – These include all large types of numeric values that do not come under either floating-point
data type or integer data type.
4. Floating-point – These refer to all the real number values or decimal points, such as 40.1, 820.673,
5.9, etc.
5. Void – This term refers to no values at all. We mostly use this data type when defining the functions in
a program.
KEYWORDS AND DATATYPES IN C LANGUAGE

Let’s consider a scenario of a company.

A company stores various data of their employee such as Name, Employee ID, Age, Salary, Address,
Phone No, etc. Now, these data are values containing alphabets, numbers, etc, so to make the
processing of these huge data for programs easy, the information was categorized into different types:
Name: String
ID: Integer
Salary: Float or Double
Phone No: String
OPERATORS AND TYPES OF OPERATORS IN C LANGUAGE

 Operators can be defined as the symbols that help us to perform specific mathematical, relational,
bitwise, conditional, or logical computations on operands. In other words, we can say that an operator
operates the operands. For example, ‘+’ is an operator used for addition, as shown below:
 c = a + b;
 Types of operators
 C has many built in operators and can be classifies into
 1. Arithmetic operators- these operators are used to perform basic arithmetic/mathematic operations.
 2. Relational operators-these operators are used for comparing the values of the variables.
 3.Logical operators- these operators are use to combine two or more expressions.
OPERATORS AND TYPES OF OPERATORS IN C LANGUAGE
OPERATORS AND TYPES OF OPERATORS IN C LANGUAGE

Operators and types of operators in c language


OPERATORS AND TYPES OF OPERATORS IN C LANGUAGE
C IF ELSE STATEMENT

 C if-else Statement
 The if-else statement is a decision-making statement that is used to decide whether
the part of the code will be executed or not based on the specified condition (test
expression). If the given condition is true, then the code inside the if block is
executed, otherwise the code inside the else block is executed.
C IF ELSE STATEMENT
WHILE, DO WHILE AND FOR LOOP IN C

What is Loop in C?

Looping Statements in C execute the sequence of statements many times until the stated
condition becomes false. A loop in C consists of two parts, a body of a loop and a control
statement. The control statement is a combination of some conditions that direct the body
of the loop to execute until the specified condition becomes false. The purpose of the C
loop is to repeat the same code a number of times.
WHILE, DO WHILE AND FOR LOOP IN C

‘C’ programming language provides us with three types of loop constructs:


1. While Loop - In while loop, a condition is evaluated before processing a body of the loop. If a condition is true
then and only then the body of a loop is executed.(to write a while loop write while and then in brackets(a!=b) and
then write the code you want to run in curly brackets)
2. Do-While Loop - In a do…while loop, the condition is always executed after the body of a loop. It is also called
an exit-controlled loop. (In do while loop we write do and then the code in curly bracket and then while and
conditions in brackets, in do while loop the code is executed no matter whether the condition is true or false and
then the condition is checked if its false the code won’t rerun. While in the while loop first the condition is
checked and the given code will only run if the condition is true.
3. For Loop - In a for loop, the initial value is performed only once, then the condition tests and compares the
counter to a fixed value after each iteration, stopping the for loop when false is returned.( it gives us more control
over loops, to write a for loop in c program we can type for and in the brackets we can initialize a control variable
like (int I =1;) and then after semicolon we can have our condition like I<=3, and then if we want to increment or
decrement the value we can add i++ or i--
WHILE, DO WHILE AND FOR LOOP IN C

The control conditions must be well defined and specified otherwise the loop will execute an infinite number
of times. The loop that does not stop executing and processes the statements number of times is called as an
infinite loop. An infinite loop is also called as an “Endless loop.”
ARRAY, POINTERS, STRINGS AND COMMENTS.

Array is the collection of data items of the same data type. You can declare a array as same as variable int
area [10]; and in square bracket the size of the array, but you can also have empty square brackets int
numbers[ ]={1,2,3} if you assign the value to the array elements at the time of array initialization. Index of
the first item in the array will be 0, you can also work on any dimensional array let it be one dimensional,
two dimensional or three dimensional.
A variable that stores another variable’s address is called a pointer. Declaring a pointer is almost same as
declaring a variable we need to add a star sign before the variable name for the pointer. A pointer that stores
the address of the another pointer variable is called double pointer .
a string is an array of characters. To declare a string in c program we use the datatype char and then the
string name and in the brackets string size and then your string char imp_message[6]=“string”; . To print or
scan a string we need to use %s as a format specifier.
We use // (double forward slash) to write a single line comment in c and multiline comments starts with a /*
and ends with a * and /.
COMPILE C PROGRAM WITH GCC

To compile your c program using gcc you can type gcc and then the file name gcc
filename.c
and we use ./a.out for linux and .\a.exe for windows.
THANK YOU

You might also like