C Programming Language Tutorial for beginners - JavaTpoint
-
Upload
plot-no-6-near-mmx-mall-mohan-nagar-ghaziabad-pin-201007 -
Category
Education
-
view
2.279 -
download
9
description
Transcript of C Programming Language Tutorial for beginners - JavaTpoint
![Page 1: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/1.jpg)
C Programming Language tutorial
Powered by:-www.javatpoint.com
![Page 2: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/2.jpg)
What is c language:-C is mother language of all programming
language. It is system programming language. It is procedure-oriented programming
language. It is also called mid level programming
language.
![Page 3: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/3.jpg)
History of c language:- C programming language was developed in 1972
by Dennis Ritchie at bell laboratories of AT&T(American Telephone & Telegraph), located in U.S.A.
Dennis Ritchie is known as founder of c language.
It was developed to be used in UNIX Operating system.
It inherits many features of previous languages such as B and BPCL.
![Page 4: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/4.jpg)
Language year Developed By
ALGOL 1960 International Group
BPCL 1967 Martin Richards
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
![Page 5: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/5.jpg)
Features of C Language:-
There are many features of c language are given below.1) Simple2) Machine Independent or Portable3) Mid-level programming language4) structured programming language5) Rich Library6) Memory Management7) Fast Speed8) Pointers9) Recursion10) Extensible
![Page 6: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/6.jpg)
First Program of C Language:-
#include <stdio.h> #include <conio.h> void main(){ printf("Hello C Language"); getch(); }
![Page 7: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/7.jpg)
Describe the C Program:-
#include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .
#include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file.
void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value.
printf() The printf() function is used to print data on the console.
getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.
![Page 8: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/8.jpg)
Output of Program is:-
Hello C Language
![Page 9: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/9.jpg)
Input output function:-
There are two input output function of c language.1) First is printf()2) Second is scanf() printf() function is used for output. It prints the
given statement to the console. Syntax of printf() is given below: printf(“format string”,arguments_list); Format string can be %d(integer), %c(character),
%s(string), %f(float) etc.
![Page 10: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/10.jpg)
scanf() Function: is used for input. It reads the input data from console.
scanf(“format string”,argument_list);
Note:-See more example of input-output function on:-www.javatpoint.com/printf-scanf
![Page 11: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/11.jpg)
Data types in C language:-There are four types of 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
![Page 12: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/12.jpg)
Keywords in C Language:-A keyword is a reserved word. You
cannot use it as a variable name, constant name etc.
There are 32 keywords in C language as given below:
auto break case char const continue
default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
![Page 13: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/13.jpg)
Operators in C language:- There are following types of operators to perform
different types of operations in C language.1) Arithmetic Operators2) Relational Operators3) Shift Operators4) Logical Operators5) Bitwise Operators6) Ternary or Conditional Operators7) Assignment Operator8) Misc Operator
![Page 14: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/14.jpg)
Control statement in C language:-1) if-else2) switch3) loops4) do-while loop5) while loop6) for loop7) break 8) continue
![Page 15: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/15.jpg)
C if else statement:-There are many ways to use if statement
in C language:1) If statement2) If-else statement3) If else-if ladder4) Nested if
![Page 16: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/16.jpg)
if statement:- In if statement is used to execute the code
if condition is true.syntax:-if(expression){//code to be execute}
![Page 17: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/17.jpg)
If else statement:-The if-else statement is used to execute
the code if condition is true or false.Syntax:if(expression){ //code to be executed if condition is true }else{ //code to be executed if condition is false }
![Page 18: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/18.jpg)
If else-if ladder Statement:- The if else-if statement is used to execute one code from multiple conditions. Syntax:if(condition1){ //code to be executed if condition1 is true }else if(condition2){ //code to be executed if condition2 is true } else if(condition3){ //code to be executed if condition3 is true }
... else{ //code to be executed if all the conditions are false }
![Page 19: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/19.jpg)
if else-if ladder Statement:- Syntax:if(condition1){ //code to be executed if condition1 is true }else if(condition2){ //code to be executed if condition2 is true } else if(condition3){ //code to be executed if condition3 is true } ... else{ //code to be executed if all the conditions are false }
![Page 20: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/20.jpg)
C Switch Statement:- Syntax:switch(expression){ case value1: //code to be executed; break; //optional case value2: //code to be executed; break; //optional ...... default: code to be executed if all cases are not matched; }
![Page 21: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/21.jpg)
Loops in C language:-Loops are used to execute a block of code
or a part of program of the program several times.
Types of loops in C language:-There are 3 types of loops in c language.1) do while2) while3) for
![Page 22: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/22.jpg)
do-while loop in C:- It is better if you have to execute the code
at least once.Syntax:-do{ //code to be executed }while(condition);
![Page 23: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/23.jpg)
while loop in c language:- It is better if number of iteration is not
known by the user.Syntax:-while(condition){ //code to be executed }
![Page 24: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/24.jpg)
For loop in C language:- It is good if number of iteration is known
by the user.Syntax:-for(initialization;condition;incr/decr){ //code to be executed }
![Page 25: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/25.jpg)
C break statement:- it is used to break the execution of loop
(while, do while and for) and switch case.Syntax:-jump-statement; break;
![Page 26: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/26.jpg)
Continue statement in C language:- it is used to continue the execution of loop
(while, do while and for). It is used with if condition within the loop.
Syntax:-jump-statement; continue; Note:- you can see the example of above all
control statements on www.javatpoint.com/c-if else.
![Page 27: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/27.jpg)
Functions in C language:-To perform any task, we can create
function. A function can be called many times. It provides modularity and code reusability.
Advantage of function:-1) Code Resuability2) Code optimization
![Page 28: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/28.jpg)
Syntax to declare function:-return_type function_name(data_type para
meter...){ //code to be executed } Syntax to call function:-variable=function_name(arguments...);
![Page 29: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/29.jpg)
Call by value in C language:-In call by value, value being passed to the function is locally
stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only. It will not change the value of variable inside the caller method such as main().
![Page 30: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/30.jpg)
Example of call by value:-#include <stdio.h> #include <conio.h> void change(int num) { printf("Before adding value inside function num=%d \n",num); num=num+100; printf("After adding value inside function num=%d \n", num); } int main() { int x=100; clrscr(); printf("Before function call x=%d \n", x); change(x);//passing value in function printf("After function call x=%d \n", x); getch(); return 0; }
![Page 31: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/31.jpg)
Output:-Before function call x=100 Before adding value inside function
num=100 After adding value inside function
num=200 After function call x=100
![Page 32: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/32.jpg)
Call by reference in C:- In call by reference, original value is
modified because we pass reference (address).
![Page 33: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/33.jpg)
Example of call by Reference:-#include <stdio.h> #include <conio.h> void change(int *num) { printf("Before adding value inside function num=%d \n",*num); (*num) += 100; printf("After adding value inside function num=%d \n", *num); } int main() { int x=100; clrscr(); printf("Before function call x=%d \n", x); change(&x);//passing reference in function printf("After function call x=%d \n", x); getch(); return 0; }
![Page 34: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/34.jpg)
Output:-Before function call x=100Before adding value inside function
num=100 After adding value inside function
num=200 After function call x=200
![Page 35: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/35.jpg)
Recursion in C:- A function that calls itself, and doen't perform any
task after function call, is know as tail recursion. In tail recursion, we generally call the same function with return statement.
Syntax:-recursionfunction(){ recursionfunction();//calling self function }
![Page 36: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/36.jpg)
Array in C:- Array in C language is a collection or group of elements
(data). All the elements of array are homogeneous(similar). It has contiguous memory location.
Declaration of array:- data_type array_name[array_size]; Eg:- int marks[7]; Types of array:-1) 1-D Array2) 2-D Array
![Page 37: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/37.jpg)
Advantage of array:-1) Code Optimization2) Easy to traverse data3) Easy to sort data4) Random Access
![Page 38: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/38.jpg)
2-D Array in C:-2-d Array is represented in the form of
rows and columns, also known as matrix. It is also known as array of arrays or list of arrays.
Declaration of 2-d array:-data_type array_name[size1][size2];
![Page 39: C Programming Language Tutorial for beginners - JavaTpoint](https://reader035.fdocuments.us/reader035/viewer/2022081418/555868ccd8b42aaa7e8b4a25/html5/thumbnails/39.jpg)
Initialization of 2-d array:- int arr[3][4]={{1,2,3,4},{2,3,4,5},
{3,4,5,6}};