SlideShare a Scribd company logo
1 of 14
Download to read offline
Introduction
The C is Procedure-oriented programming language that is developed for creating
system applications that directly interact with the hardware devices such as drivers,
kernels, etc.
C programming is considered as the base for other programming languages, that is why
it is known as mother language.
It provides the core concepts like the array, strings, functions, file handling, etc. that are
being used in many languages like C++, Java, C#, etc.
C language is considered as the mother language of all the modern programming
languages because most of the compilers, JVMs, Kernels, etc. are written in C
language.
A procedure is known as a function, method, routine, subroutine, etc. A procedural
language specifies a series of steps for the program to solve the problem.
A procedural language breaks the program into functions, data structures, etc.
C is a procedural language. In C, variables and function prototypes must be declared
before being used.
C is considered as a middle-level language because it supports the feature of both
low-level and high-level languages. C language program is converted into assembly
code, it supports pointer arithmetic (low-level), but it is machine independent (a feature
of high-level).
A Low-level language is specific to one machine, i.e., machine dependent. It is
machine dependent, fast to run. But it is not easy to understand.
A High-Level language is not specific to one machine, i.e., machine independent. It is
easy to understand.
C Program
In this tutorial, all C programs are given with C compiler so that you can quickly change
the C program code.
File Name : main.c
#include <stdio.h>
1. int main(){
2. printf("Hello C Language");
3. return 0;
4. }
C programming language was developed in 1972 by Dennis Ritchie at bell laboratories
of AT&T (American Telephone & Telegraph), located in the U.S.A.
Dennis Ritchie is known as the founder of the c language.
It was developed to overcome the problems of previous languages such as B, BCPL, etc.
Initially, C language was developed to be used in UNIX operating system. It inherits
many features of previous languages such as B and BCPL.
Let's see the programming languages that were developed before C language.
Language Year Developed By
Algol 1960 International Group
BCPL 1967 Martin Richard
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K & R C 1978 Kernighan & Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization Committee
Features of C Language
C is the widely used language. It provides many features that are given below.
1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. Rich Library
5. Fast Speed
6. Recursion
Simple
C is a simple language in the sense that it provides a structured approach (to break
the problem into parts), the rich set of library functions, data types, etc.
Machine Independent or Portable
Unlike assembly language, c programs can be executed on different machines with
some machine specific changes.
Mid-level programming language
Although,C is intended to do low-level programming. It is used to develop system
applications such as kernel, driver, etc. It also supports the features of a high-level
language. That is why it is known as mid-level language.
Rich Library
C provides a lot of inbuilt functions that make the development fast.
Speed
The compilation and execution time of C language is fast since there are lesser inbuilt
functions and hence the lesser overhead.
Recursion
In C, we can call the function within the function. It provides code reusability for
every function. Recursion enables us to use the approach of backtracking.
Pointer
C provides the feature of pointers. We can directly interact with the memory by using
the pointers. We can use pointers for memory, structures, functions, array, etc.
First C Program
Before starting the abcd of C language, you need to learn how to write, compile and run
the first c program.
To write the first c program, open the C console and write the following code:
1. #include <stdio.h>
2. int main(){
3. printf("Hello C Language");
4. return 0; }
#include <stdio.h> includes the standard input output library functions. The printf()
function is defined in stdio.h .
int main() The main() function is the entry point of every program in c language.
printf() The printf() function is used to print data on the console.
return 0 The return 0 statement, returns execution status to the OS. The 0 value is
used for successful execution and 1 for unsuccessful execution.
How to compile and run the c program
There are 2 ways to compile and run the c program, by menu and by shortcut.
Flow of C Program
The C program follows many steps in execution. To understand the flow of C program
well, let us see a simple program first.
File Name : simple.c
#include <stdio.h>
5. int main(){
6. printf("Hello C Language");
7. return 0;
8. }
Flow of Execution
Let's try to understand the flow of above program by the figure given below.
1)
C program (source code) is sent to preprocessor first. The
preprocessor is responsible to convert preprocessor
directives into their respective values. The preprocessor
generates an expanded source code.
2)
Expanded source code is sent to compiler which compiles
the code and converts it into assembly code.
3)
The assembly code is sent to assembler which assembles
the code and converts it into object code. Now a simple.obj
file is generated.
4)
The object code is sent to linker which links it to the library
such as header files. Then it is converted into executable
code. A simple.exe file is generated.
5)
The executable code is sent to loader which loads it into
memory and then it is executed. After execution, output is
sent to console.
printf() and scanf() in C
The printf() and scanf() functions are used for input and output in C language. Both
functions are inbuilt library functions, defined in stdio.h (header file).
printf() function
The printf() function is used for output. It prints the given statement to the console.
The syntax of printf() function is given below:
printf("format string",argument_list);
The format string can be %d (integer), %c (character), %s (string), %f (float) etc.
scanf() function
The scanf() function is used for input. It reads the input data from the console.
scanf("format string",argument_list);
Variables in C
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.
It is a way to represent memory location through symbol so that it can be easily
identified.
Let's see the syntax to declare a variable:
type variable_list;
The example of declaring the variable is given below:
1. int a;
2. float b;
3. char c;
Here, a, b, c are variables. The int, float, char are the data types.
We can also provide values while declaring the variables as given below:
1. int a=10,b=20;//declaring 2 variable of integer type
2. float f=20.8;
3. char c='A';
Data Types in C
A data type specifies the type of data that a variable can store such as integer, floating,
character, etc.
There are the following data types in C language.
Types Data Types
Basic Data Type int, char, float, double
Derived Data Type array, pointer, structure, union
Enumeration Data Type enum
Void Data Type void
Program to print cube of given number
Let's see a simple example of c language that gets input from the user and prints the
cube of the given number.
1. #include<stdio.h>
2. int main(){
3. int number;
4. printf("enter a number:");
5. scanf("%d",&number);
6. printf("cube of number is:%d ",number*number*number);
7. return 0;
8. }
Output
enter a number:5
cube of number
is:125
The scanf("%d",&number) statement reads integer number from the console and
stores the given value in number variable.
The printf("cube of number is:%d ",number*number*number) statement prints
the cube of number on the console.
Program to print sum of 2 numbers
Let's see a simple example of input and output in C language that prints addition of 2
numbers.
#include<stdio.h>
1. int main(){
2. int x=0,y=0,result=0;
3.
4. printf("enter first number:");
5. scanf("%d",&x);
6. printf("enter second number:");
7. scanf("%d",&y);
8.
result=x+y;
printf("sum of 2 numbers:%d ",result);
return 0;
}
Output
enter first number:9
enter second number:9
sum of 2 numbers:18
Rules for defining variables
o A variable name must be start with the alphabet, and underscore only. It can't
start with a digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.
Valid variable names Invalid variable names
1.
2. int a;
3. int _ab;
4. int a30;
1. int 2;
2. int a b;
3. int long;
Types of Variables in C
There are many types of variables in c:
1. local variable
2. global variable
3. static variable
4. automatic variable
5. external variable
Local Variable
A variable that is declared inside the
function or block is called a local variable.
It must be declared at the start of the
block.
1. void function1(){
2. int x=10;//local variable
3. }
You must have to initialize the local variable before it is used.
Global Variable
A variable that is declared outside the
function or block is called a global variable.
Any function can change the value of the
global variable. It is available to all the
functions.
1. int value=20;//global variable
2. void function1(){
3. int x=10;//local variable
4. }
It must be declared at the start of the block.
Static Variable
A variable that is declared with the static
keyword is called static variable.
1. void function1(){
2. int x=10;//local variable
3. static int y=10;//static variable
4. x=x+1;
5. y=y+1;
6. printf("%d,%d",x,y);
7. }
It retains its value between multiple function calls.
If you call this function many times, the local variable will print the same value for
each function call, e.g, 11,11,11 and so on. But the static variable will print the
incremented value in each function call, e.g. 11, 12, 13 and so on.
Automatic Variable
All variables in C that are declared
inside the block, are automatic
variables by default. We can explicitly
declare an automatic variable
using auto keyword.
1. void main(){
2. int x=10;//local variable (also automatic)
3. auto int y=20;//automatic variable
4. }
External Variable
We can share a variable in multiple C source files by using an external variable. To
declare an external variable, you need to use extern keyword.
File name : myfile.h
1. extern int x=10;
2. //external variable (also global)
File name : program1.c
1. #include "myfile.h"
2. #include <stdio.h>
3. void printValue(){
4. printf("Global variable: %d", global_variable);
5. }
Basic Data Types
Let's see the basic data types. Its size is given according to 32-bit architecture.
Data
Types
Memory Size Range
char 1 byte −128 to 127
short 2 byte −32,768 to 32,767
int 2 byte −32,768 to 32,767
short
int
2 byte −32,768 to 32,767
long
int
4 byte -2,147,483,648 to 2,147,483,647
float 4 byte
double 8 byte
long
double
10 byte
Keywords in C
A keyword is a reserved word. You cannot use it as a variable name, constant name,
etc. There are only 32 reserved words (keywords) in the C language.
A list of 32 keywords in the c language is given below:
do if char enum break signed const register
while else int extern continue unsigned struct sizeof
for goto float void default union return static
switch case double volatile auto typedef short long
C Operators
An operator is simply a symbol that is used to perform operations. There can be many
types of operations like arithmetic, logical, bitwise, etc.
There are following types of operators to perform different types of operations in C
language.
o Arithmetic Operators
o Relational Operators
o Shift Operators
o Logical Operators
o Bitwise Operators
o Ternary or Conditional Operators
o Assignment Operator
o Misc Operator
Precedence of Operators in C
The precedence of operator specie’s that which operator will be evaluated first and next.
The associativity specifies the operator direction to be evaluated; it may be left to right
or right to left.
Let's understand the precedence by the example given below:
1. int value=10+20*10;
The value variable will contain 210 because * (multiplicative operator) is evaluated
before + (additive operator).
Category Operator Associativity
Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & sizeof Right to left
Multiplicative * / % Left to right
Additive + - Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left
Comma , Left to right
Comments in C
Comments in C language are used to provide information about lines of code. It is widely
used for documenting code. There are 2 types of comments in the C language.
1. Single Line Comments
2. Multi-Line Comments
Single Line Comments Multi Line Comments
1. #include<stdio.h>
2. int main(){
3. //printing information
4. printf("Hello C");
5. return 0;
6. }
1. #include<stdio.h>
2. int main(){
3. /*printing information
4. Multi-Line Comment*/
5. printf("Hello C");
6. return 0;
7. }
7. Single line comments are represented by
double slash //. Let's see an example of a
single line comment in C.
8. Multi-Line comments are represented by
slash asterisk * ... *. It can occupy many
lines of code, but it can't be nested
Escape Sequence in C
An escape sequence in C language is a sequence of characters that doesn't represent
itself when used inside string literal or character.
It is composed of two or more characters starting with backslash . For example: n
represents new line.
Constants in C
A constant is a value or variable that can't be changed in the program, for example: 10,
20, 'a', 3.4, "c programming" etc.
2 ways to define constant in C
There are two ways to define constant in C programming.
1. const keyword
2. #define pre-processor
const keyword #define pre-processor
1. #include<stdio.h>
2. int main(){
3. const float PI=3.14;
4. printf("The value of PI is: %f",PI);
5. return 0;
6. }
1. #include <stdio.h>
2. #define PI 3.14
3. main() {
4. printf("%f",PI);
5. }
We can’t modify a const object
The const keyword is used to define constant in C programming.
The #define pre-processor directive is used to define constant or micro substitution. It
can use any basic data type.
Syntax:
1. #define token value
Let's see an example of #define to create a macro.
1. #include <stdio.h>
2. #define MIN(a,b) ((a)<(b)?(a):(b))
3. void main() {
4. printf("Minimum between 10 and 20 is: %dn", MIN(10,20));
5. }
Output:
Minimum between 10
and 20 is: 10

More Related Content

What's hot

Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examplesabclearnn
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and outputMythiliA5
 
Software Re-Engineering in Software Engineering SE28
Software Re-Engineering in Software Engineering SE28Software Re-Engineering in Software Engineering SE28
Software Re-Engineering in Software Engineering SE28koolkampus
 
Time Sensitive Networking in the Linux Kernel
Time Sensitive Networking in the Linux KernelTime Sensitive Networking in the Linux Kernel
Time Sensitive Networking in the Linux Kernelhenrikau
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdfNehaSpillai1
 
Mc call's software quality model
Mc call's software quality modelMc call's software quality model
Mc call's software quality modelYatharth Aggarwal
 
Loader and Its types
Loader and Its typesLoader and Its types
Loader and Its typesParth Dodiya
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopJanani Selvaraj
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Janki Shah
 
2. bit fields union enum
2. bit fields  union  enum2. bit fields  union  enum
2. bit fields union enumhasan Mohammad
 
Software design principles
Software design principlesSoftware design principles
Software design principlesMd.Mojibul Hoque
 
Capability Maturity Model (CMM) in Software Engineering
Capability Maturity Model (CMM) in Software EngineeringCapability Maturity Model (CMM) in Software Engineering
Capability Maturity Model (CMM) in Software EngineeringFaizanAhmad340414
 

What's hot (20)

Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
 
MPI
MPIMPI
MPI
 
Software Re-Engineering in Software Engineering SE28
Software Re-Engineering in Software Engineering SE28Software Re-Engineering in Software Engineering SE28
Software Re-Engineering in Software Engineering SE28
 
Time Sensitive Networking in the Linux Kernel
Time Sensitive Networking in the Linux KernelTime Sensitive Networking in the Linux Kernel
Time Sensitive Networking in the Linux Kernel
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Mc call's software quality model
Mc call's software quality modelMc call's software quality model
Mc call's software quality model
 
Loader and Its types
Loader and Its typesLoader and Its types
Loader and Its types
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Need of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oopNeed of OOPs and Programming,pop vs oop
Need of OOPs and Programming,pop vs oop
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
 
Google File System
Google File SystemGoogle File System
Google File System
 
2. bit fields union enum
2. bit fields  union  enum2. bit fields  union  enum
2. bit fields union enum
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
Capability Maturity Model (CMM) in Software Engineering
Capability Maturity Model (CMM) in Software EngineeringCapability Maturity Model (CMM) in Software Engineering
Capability Maturity Model (CMM) in Software Engineering
 

Similar to Learn c language Important topics ( Easy & Logical, & smart way of learning)

C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfComedyTechnology
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programmingMithun DSouza
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
Copy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptxCopy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptxrahulrajbhar06478
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.pptatulchaudhary821
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTBatra Centre
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdfRajb54
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)aaravSingh41
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxSanketShah544615
 

Similar to Learn c language Important topics ( Easy & Logical, & smart way of learning) (20)

The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
 
C programming notes
C programming notesC programming notes
C programming notes
 
Copy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptxCopy of UNIT 2 -- Basics Of Programming.pptx
Copy of UNIT 2 -- Basics Of Programming.pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
Basic c
Basic cBasic c
Basic c
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 
C Lang notes.ppt
C Lang notes.pptC Lang notes.ppt
C Lang notes.ppt
 
Unit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptxUnit-2_Getting Started With ‘C’ Language (3).pptx
Unit-2_Getting Started With ‘C’ Language (3).pptx
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 

More from Rohit Singh

Rohit RajSingh_ApplicationForm.pdf
Rohit RajSingh_ApplicationForm.pdfRohit RajSingh_ApplicationForm.pdf
Rohit RajSingh_ApplicationForm.pdfRohit Singh
 
Data entry exclusive+
Data entry exclusive+ Data entry exclusive+
Data entry exclusive+ Rohit Singh
 
Custom pagination
Custom paginationCustom pagination
Custom paginationRohit Singh
 
Sql exception and class notfoundexception
Sql exception and class notfoundexceptionSql exception and class notfoundexception
Sql exception and class notfoundexceptionRohit Singh
 
Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)Rohit Singh
 
Project ppt, Learn Project Java
Project ppt, Learn Project JavaProject ppt, Learn Project Java
Project ppt, Learn Project JavaRohit Singh
 
5g networking technology
5g networking technology5g networking technology
5g networking technologyRohit Singh
 
First program of C ( Complete Explanation )
First program of C ( Complete Explanation )First program of C ( Complete Explanation )
First program of C ( Complete Explanation )Rohit Singh
 
CCNA Course Training Presentation
CCNA Course Training PresentationCCNA Course Training Presentation
CCNA Course Training PresentationRohit Singh
 
Software testing basic
Software testing basicSoftware testing basic
Software testing basicRohit Singh
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsRohit Singh
 

More from Rohit Singh (15)

Rohit RajSingh_ApplicationForm.pdf
Rohit RajSingh_ApplicationForm.pdfRohit RajSingh_ApplicationForm.pdf
Rohit RajSingh_ApplicationForm.pdf
 
date2.docx
date2.docxdate2.docx
date2.docx
 
Data entry exclusive+
Data entry exclusive+ Data entry exclusive+
Data entry exclusive+
 
Assignment 1
Assignment 1Assignment 1
Assignment 1
 
Custom pagination
Custom paginationCustom pagination
Custom pagination
 
Sql exception and class notfoundexception
Sql exception and class notfoundexceptionSql exception and class notfoundexception
Sql exception and class notfoundexception
 
Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)Angular Part 3 (Basic knowledge)
Angular Part 3 (Basic knowledge)
 
Project ppt, Learn Project Java
Project ppt, Learn Project JavaProject ppt, Learn Project Java
Project ppt, Learn Project Java
 
5g networking technology
5g networking technology5g networking technology
5g networking technology
 
First program of C ( Complete Explanation )
First program of C ( Complete Explanation )First program of C ( Complete Explanation )
First program of C ( Complete Explanation )
 
C language
C languageC language
C language
 
CCNA Course Training Presentation
CCNA Course Training PresentationCCNA Course Training Presentation
CCNA Course Training Presentation
 
Html Basic
Html Basic Html Basic
Html Basic
 
Software testing basic
Software testing basicSoftware testing basic
Software testing basic
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 

Recently uploaded

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 

Recently uploaded (20)

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 

Learn c language Important topics ( Easy & Logical, & smart way of learning)

  • 1. Introduction The C is Procedure-oriented programming language that is developed for creating system applications that directly interact with the hardware devices such as drivers, kernels, etc. C programming is considered as the base for other programming languages, that is why it is known as mother language. It provides the core concepts like the array, strings, functions, file handling, etc. that are being used in many languages like C++, Java, C#, etc. C language is considered as the mother language of all the modern programming languages because most of the compilers, JVMs, Kernels, etc. are written in C language. A procedure is known as a function, method, routine, subroutine, etc. A procedural language specifies a series of steps for the program to solve the problem. A procedural language breaks the program into functions, data structures, etc. C is a procedural language. In C, variables and function prototypes must be declared before being used. C is considered as a middle-level language because it supports the feature of both low-level and high-level languages. C language program is converted into assembly code, it supports pointer arithmetic (low-level), but it is machine independent (a feature of high-level). A Low-level language is specific to one machine, i.e., machine dependent. It is machine dependent, fast to run. But it is not easy to understand. A High-Level language is not specific to one machine, i.e., machine independent. It is easy to understand. C Program In this tutorial, all C programs are given with C compiler so that you can quickly change the C program code. File Name : main.c #include <stdio.h> 1. int main(){ 2. printf("Hello C Language"); 3. return 0; 4. }
  • 2. C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. Dennis Ritchie is known as the founder of the c language. It was developed to overcome the problems of previous languages such as B, BCPL, etc. Initially, C language was developed to be used in UNIX operating system. It inherits many features of previous languages such as B and BCPL. Let's see the programming languages that were developed before C language. Language Year Developed By Algol 1960 International Group BCPL 1967 Martin Richard B 1970 Ken Thompson Traditional C 1972 Dennis Ritchie K & R C 1978 Kernighan & Dennis Ritchie ANSI C 1989 ANSI Committee ANSI/ISO C 1990 ISO Committee C99 1999 Standardization Committee Features of C Language C is the widely used language. It provides many features that are given below. 1. Simple 2. Machine Independent or Portable 3. Mid-level programming language 4. Rich Library 5. Fast Speed 6. Recursion
  • 3. Simple C is a simple language in the sense that it provides a structured approach (to break the problem into parts), the rich set of library functions, data types, etc. Machine Independent or Portable Unlike assembly language, c programs can be executed on different machines with some machine specific changes. Mid-level programming language Although,C is intended to do low-level programming. It is used to develop system applications such as kernel, driver, etc. It also supports the features of a high-level language. That is why it is known as mid-level language. Rich Library C provides a lot of inbuilt functions that make the development fast. Speed The compilation and execution time of C language is fast since there are lesser inbuilt functions and hence the lesser overhead. Recursion In C, we can call the function within the function. It provides code reusability for every function. Recursion enables us to use the approach of backtracking. Pointer C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array, etc. First C Program Before starting the abcd of C language, you need to learn how to write, compile and run the first c program. To write the first c program, open the C console and write the following code: 1. #include <stdio.h> 2. int main(){ 3. printf("Hello C Language"); 4. return 0; }
  • 4. #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h . int main() The main() function is the entry point of every program in c language. printf() The printf() function is used to print data on the console. return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution. How to compile and run the c program There are 2 ways to compile and run the c program, by menu and by shortcut. Flow of C Program The C program follows many steps in execution. To understand the flow of C program well, let us see a simple program first. File Name : simple.c #include <stdio.h> 5. int main(){ 6. printf("Hello C Language"); 7. return 0; 8. } Flow of Execution Let's try to understand the flow of above program by the figure given below.
  • 5. 1) C program (source code) is sent to preprocessor first. The preprocessor is responsible to convert preprocessor directives into their respective values. The preprocessor generates an expanded source code. 2) Expanded source code is sent to compiler which compiles the code and converts it into assembly code. 3) The assembly code is sent to assembler which assembles the code and converts it into object code. Now a simple.obj file is generated. 4) The object code is sent to linker which links it to the library such as header files. Then it is converted into executable code. A simple.exe file is generated. 5) The executable code is sent to loader which loads it into memory and then it is executed. After execution, output is sent to console. printf() and scanf() in C The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).
  • 6. printf() function The printf() function is used for output. It prints the given statement to the console. The syntax of printf() function is given below: printf("format string",argument_list); The format string can be %d (integer), %c (character), %s (string), %f (float) etc. scanf() function The scanf() function is used for input. It reads the input data from the console. scanf("format string",argument_list); Variables in C 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. It is a way to represent memory location through symbol so that it can be easily identified. Let's see the syntax to declare a variable: type variable_list; The example of declaring the variable is given below: 1. int a; 2. float b; 3. char c; Here, a, b, c are variables. The int, float, char are the data types. We can also provide values while declaring the variables as given below: 1. int a=10,b=20;//declaring 2 variable of integer type 2. float f=20.8; 3. char c='A';
  • 7. Data Types in C A data type specifies the type of data that a variable can store such as integer, floating, character, etc. There are the following data types in C language. Types Data Types Basic Data Type int, char, float, double Derived Data Type array, pointer, structure, union Enumeration Data Type enum Void Data Type void Program to print cube of given number Let's see a simple example of c language that gets input from the user and prints the cube of the given number. 1. #include<stdio.h> 2. int main(){ 3. int number; 4. printf("enter a number:"); 5. scanf("%d",&number); 6. printf("cube of number is:%d ",number*number*number); 7. return 0; 8. } Output enter a number:5 cube of number is:125
  • 8. The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable. The printf("cube of number is:%d ",number*number*number) statement prints the cube of number on the console. Program to print sum of 2 numbers Let's see a simple example of input and output in C language that prints addition of 2 numbers. #include<stdio.h> 1. int main(){ 2. int x=0,y=0,result=0; 3. 4. printf("enter first number:"); 5. scanf("%d",&x); 6. printf("enter second number:"); 7. scanf("%d",&y); 8. result=x+y; printf("sum of 2 numbers:%d ",result); return 0; } Output enter first number:9 enter second number:9 sum of 2 numbers:18 Rules for defining variables o A variable name must be start with the alphabet, and underscore only. It can't start with a digit. o No whitespace is allowed within the variable name. o A variable name must not be any reserved word or keyword, e.g. int, float, etc. Valid variable names Invalid variable names 1. 2. int a; 3. int _ab; 4. int a30; 1. int 2; 2. int a b; 3. int long;
  • 9. Types of Variables in C There are many types of variables in c: 1. local variable 2. global variable 3. static variable 4. automatic variable 5. external variable Local Variable A variable that is declared inside the function or block is called a local variable. It must be declared at the start of the block. 1. void function1(){ 2. int x=10;//local variable 3. } You must have to initialize the local variable before it is used. Global Variable A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions. 1. int value=20;//global variable 2. void function1(){ 3. int x=10;//local variable 4. } It must be declared at the start of the block. Static Variable A variable that is declared with the static keyword is called static variable. 1. void function1(){ 2. int x=10;//local variable 3. static int y=10;//static variable 4. x=x+1; 5. y=y+1; 6. printf("%d,%d",x,y); 7. } It retains its value between multiple function calls. If you call this function many times, the local variable will print the same value for each function call, e.g, 11,11,11 and so on. But the static variable will print the incremented value in each function call, e.g. 11, 12, 13 and so on.
  • 10. Automatic Variable All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using auto keyword. 1. void main(){ 2. int x=10;//local variable (also automatic) 3. auto int y=20;//automatic variable 4. } External Variable We can share a variable in multiple C source files by using an external variable. To declare an external variable, you need to use extern keyword. File name : myfile.h 1. extern int x=10; 2. //external variable (also global) File name : program1.c 1. #include "myfile.h" 2. #include <stdio.h> 3. void printValue(){ 4. printf("Global variable: %d", global_variable); 5. } Basic Data Types Let's see the basic data types. Its size is given according to 32-bit architecture. Data Types Memory Size Range char 1 byte −128 to 127 short 2 byte −32,768 to 32,767 int 2 byte −32,768 to 32,767 short int 2 byte −32,768 to 32,767 long int 4 byte -2,147,483,648 to 2,147,483,647 float 4 byte
  • 11. double 8 byte long double 10 byte Keywords in C A keyword is a reserved word. You cannot use it as a variable name, constant name, etc. There are only 32 reserved words (keywords) in the C language. A list of 32 keywords in the c language is given below: do if char enum break signed const register while else int extern continue unsigned struct sizeof for goto float void default union return static switch case double volatile auto typedef short long C Operators An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc. There are following types of operators to perform different types of operations in C language. o Arithmetic Operators o Relational Operators o Shift Operators o Logical Operators o Bitwise Operators o Ternary or Conditional Operators o Assignment Operator o Misc Operator Precedence of Operators in C
  • 12. The precedence of operator specie’s that which operator will be evaluated first and next. The associativity specifies the operator direction to be evaluated; it may be left to right or right to left. Let's understand the precedence by the example given below: 1. int value=10+20*10; The value variable will contain 210 because * (multiplicative operator) is evaluated before + (additive operator). Category Operator Associativity Postfix () [] -> . ++ - - Left to right Unary + - ! ~ ++ - - (type)* & sizeof Right to left Multiplicative * / % Left to right Additive + - Left to right Shift << >> Left to right Relational < <= > >= Left to right Equality == != Left to right Bitwise AND & Left to right Bitwise XOR ^ Left to right Bitwise OR | Left to right Logical AND && Left to right Logical OR || Left to right Conditional ?: Right to left Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left Comma , Left to right
  • 13. Comments in C Comments in C language are used to provide information about lines of code. It is widely used for documenting code. There are 2 types of comments in the C language. 1. Single Line Comments 2. Multi-Line Comments Single Line Comments Multi Line Comments 1. #include<stdio.h> 2. int main(){ 3. //printing information 4. printf("Hello C"); 5. return 0; 6. } 1. #include<stdio.h> 2. int main(){ 3. /*printing information 4. Multi-Line Comment*/ 5. printf("Hello C"); 6. return 0; 7. } 7. Single line comments are represented by double slash //. Let's see an example of a single line comment in C. 8. Multi-Line comments are represented by slash asterisk * ... *. It can occupy many lines of code, but it can't be nested Escape Sequence in C An escape sequence in C language is a sequence of characters that doesn't represent itself when used inside string literal or character. It is composed of two or more characters starting with backslash . For example: n represents new line. Constants in C A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc. 2 ways to define constant in C There are two ways to define constant in C programming. 1. const keyword 2. #define pre-processor
  • 14. const keyword #define pre-processor 1. #include<stdio.h> 2. int main(){ 3. const float PI=3.14; 4. printf("The value of PI is: %f",PI); 5. return 0; 6. } 1. #include <stdio.h> 2. #define PI 3.14 3. main() { 4. printf("%f",PI); 5. } We can’t modify a const object The const keyword is used to define constant in C programming. The #define pre-processor directive is used to define constant or micro substitution. It can use any basic data type. Syntax: 1. #define token value Let's see an example of #define to create a macro. 1. #include <stdio.h> 2. #define MIN(a,b) ((a)<(b)?(a):(b)) 3. void main() { 4. printf("Minimum between 10 and 20 is: %dn", MIN(10,20)); 5. } Output: Minimum between 10 and 20 is: 10