SlidePub
Home
Categories
Login
Register
Home
General
C+for+beginners (2).pdf hsudiksbdjdidkdnjd
C+for+beginners (2).pdf hsudiksbdjdidkdnjd
itzvenkatesh21
8 views
48 slides
May 01, 2024
Slide
1
of 48
Previous
Next
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
40
41
42
43
44
45
46
47
48
About This Presentation
Hsjjdjrn
Size:
918.29 KB
Language:
en
Added:
May 01, 2024
Slides:
48 pages
Slide Content
Slide 1
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C for Beginners
Slide 2
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Agenda
•Introduction to C
•Variables in C
•Datatypes in C
•Input / Output in C
•Operators in C
•C Control Statements
•Arrays in C
•Functions in C
•Strings in C
•Structures and Union
•Pointers in C
Slide 3
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to C
Slide 4
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
•CwasfirstintroducedbyDennisRitchie.
•Cisaprocedure-orientedlanguage.
•Cisawidelyusedandpopularprogramminglanguagefordevelopingsystemapplicationsoftware.
•Itcanbecalledasamid-levelprogramminglanguage.
Slide 5
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Introduction to C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Features:
Some of the features of C Programming are:-
•Easy to learn
•Structured Programming language
•Machine Independent or Portable
•Powerful
•Used in low-level as well as high level applications
Slide 6
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Basic block of a C Program
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Preproccesor directives
Global declarations;
void main()
{
local declarations;
statement 1;
statement 2;
:
statement n;
}
User defined functions
Slide 7
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Comments
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
/* This is my First C Program
Author name: */
# include<stdio.h>
#include<conio.h>
void main()
{
printf(“C Programming”); // Single line Comment
getch();
}
Slide 8
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Tokens
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Ctokensaresmallestindividualunitsinaprogram.
●Identifiers-userdefinednames/abbreviations
●Keywords-wordswhicharespecifictoClanguage
●Constants-valueswhichdon'tchange
●Strings-sequenceofcharacters
●Operators-actonoperandsandgeneratesoutput
●SpecialSymbols-usedforpreprocessordirectives(#)
Slide 9
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Variables in C
Slide 10
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Variables in C
WhatisaVariable?
•It’sanamegiventoamemorylocationwherethevalueisnotfixed,itcanchangewiththecourseof
time.Ex:intnum;
Syntax:
datatypevariable_name;
Assignment:
variable_name=value
Slide 11
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
ScopeofaVariable
•Scopegenerallyspeaksaboutthevisibilityofvariables.
-localvariableandglobalvariable
Local Global
Variables in C
void main ()
{
introllno= 10;
}
inty = 50;
void main ()
{
intx = 100;
}
Slide 12
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Data Types in C
Slide 13
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Data Types in C
Data Types
Primitive Data type Derived Data type User Defined type
Boolean
Character
Integer
Float
Double
Void
Array
Pointer
References
Structure
Union
Enum
Slide 14
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Typecasting
•C allows for conversions between the basic data types
-Implicit and Explicit
Data Types in C
intnum= 5 + 13.75; // num= 18
float a = 5.25;
intb = (int) a; // b = 5
Implicit conversion Explicit conversion
Slide 15
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Input / Output in C
Slide 16
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Input / Output in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
InputandOutputfunctionsinCare:-
•printf()andscanf()
•gets()andputs()
•getchar()andputchar()
Slide 17
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Input / Output in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
FormatSpecifiers:-
Theformatspecifierswillinformthescanf()function,whatkindofinputisbeingfedthroughinput
device.Italsotellsprintf()functionwhattypeofdatahastobeprintedontheoutputdevice.
•%d –Integer
•%c –Character
•%s –String
•%f -Float
Slide 18
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators in C
Slide 19
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
•Cprimarilysupports5typesofoperators
Arithmetic Relational Bitwise
Logical Assignment
Slide 20
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
ArithmeticOperators:-
•Usedformathematicaloperations
•Wehaveunaryandbinaryoperators
•Unary–(++,--)
•Binary–(+,-,*,/,%)
RelationalOperators:-
•Usedtocomparethevaluesoftwooperands
•Someofthemare(<,<=,>=,==)
•Wecanalsocheckforequalityofoperands,whetheranoperandisgreaterorsmallerthanthe
other.
Slide 21
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
LogicalOperators:
•TocombineoneormultipleconditionswecanuseLogicaloperators.
•LogicaloperatorsalwaysgiveusaBooleanvalue,i.e.trueorfalse
•Someofthemare(&&-AND,||-OR,!–NOT)
BitwiseOperators:-
•Wecanperformbit-leveloperationsontheoperands.
•Someofthemare(&-bitwiseAND,|-bitwiseOR)
•Itconvertsthemtobit-levelfirstandthenperformstheoperations.
Slide 22
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Operators in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
AssignmentOperator:-
•Itisusedtoassignavaluetoagivenvariable.
•Thevalueontherightsideoftheassignmentoperatorisassignedtooperandatleftside.
•Wealsohavesomeshorthandassignmentoperators(+=,-=,/=).
.
Slide 23
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
Slide 24
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
ConditionalStatements:-
•Alsoknownasselectionstatements.
•Basedontheconditionsspecifiedwecanmakesomedecisions.
•AnytimeweexecuteconditionalstatementswegetaBooleanvalueinreturn.
•Iftheconditionexecutedreturnsatruevalue,asetofstatementsareexecutedelseanothersetof
statementsareexecuted.
Slide 25
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Theifstatement:-
•Selectionandexecutionofstatementsbasedonagivenconditionisdonebytheifstatement.
Syntax:
if(condition)
{
statement1;
statement2;
}
Slide 26
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Theif-elsestatement:-
•Dependingontheresultofthecondition,theif-elsestatementexecutesoneofthetwopotential
statements.
Syntax:
if(condition)
{
statement1; //ifblock
statement2;
}
else
{
statement3: //elseblock
}
Slide 27
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
TheNestedif-elsestatement:-
•Anestedif-elsecontainsoneormoreif-elsestatements.
if(condition1)
{
statement1;
if(condition2)
statement2;
else
statement3;
}
else
{
statement3:
}
Slide 28
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Loops:-
•Loopsareusedtore-executeapartofacodeagivennumberoftimes,dependinguponthe
conditionspecified.
Entrycontrolled:-
•Theconditionischeckedeach-timebeforeenteringtheloop.Iftheconditionissatisfiedthenonly
theloopbodygetsexecuted.Theloopbodydoesnotgetexecutediftheconditionisfalseinthe
firstiteration.
Slide 29
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Entrycontrolledloopsare:-
1)Forloop
Syntax:
for(i=0;i<n;i++){
//dosomething
}
2)WhileLoop
Syntax:
while(conditionisTrue){
//dosomething
}
Slide 30
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Switchcase:-
●Theswitchstatementworksasamultiwaybranchstatement.
●It’samodifiedformofif-else.
●It’sacommonalternativetotheifstatementwhenyouwanttogetmultipleresults.
●Defaultconditiongetsexecutedwhennoconditionsaremet.
Slide 31
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
C Control Statements
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Switchcase:-
#include<stdio.h>
#include<conio.h>
void main(){
intn= 1;
switch (n)
{
case 1: Statement 1;
break;
case 2: Statement 2;
break;
default: Statement;
}
Slide 32
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Arrays in C
Slide 33
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Arrays in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Anarrayisacollectionofelementswherethedatatypesofalltheelementsaresame.
●Anarraystoresalltheelementsincontiguousmemorylocations.
●Everyelementinanarrayhasaspecifiedindex.
●SizeofanarrayinCisfixedatthetimeofdefinition
WehavetwotypesinArrays:
Singledimensional
Multi-dimensional
1 x 3 Array
2x 3 Array
Slide 34
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Arrays in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Definition:
AnarraycanbedefinedinthefollowingmannerinC:
Data_typename_of_array>[<size_of_array>]
Note:Sizeofanarrayshouldalwaysbeanintegeritcannotbearealvalue.
Example:
inta[10]; //singledimensionalarray
floatb[3][3];//float-dimensionalarray
Slide 35
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Arrays in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Arrayinitialization:
1)StaticInitialization
inta[10]={0,1,2,3,4,5,6}
charc[5]={‘h’,’e’,’l’,’l’,’o’}
2)DynamicInitialization
inta[10]; //arrayiscreatedwithgarbagevalue
for(inti=0;i<10;i++)
scanf(“%d”,&a[i]);
Slide 36
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Functions in C
Slide 37
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Functions in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Functionsareblocksofcodewhichareusedtoperformspecifictasks.
●InCafunctionneedstobedeclaredbeforeit’sused.
●Functionshaveafunctiondefinition,functionbodyandareturntype.
●Functionswithreturntypeexceptvoidneedstoreturnavalueattheend.
●Functionswithreturntypevoiddonotreturnanyvalue.
●Arecursivefunctioncancallitselfduringthecourseofexecutionofaprogram.
Slide 38
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Functions in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
AFunctionexample:
intsum(inta,intb)
{
returna+b;
}
voidmain()
{
printf(“%d”,sum(5,10));
}
Slide 39
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Strings in C
Slide 40
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Strings in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Stringsareusedtostoresequenceofcharactersasinformation.
●string.hheaderfileprovidessomebuilt-instringmanipulationfunctions.
Stringscanbeinitializedinfollowingways:-
chara[5]={‘H’,’o’,’l’,’a’};
chara[]=“Hola”;
Slide 41
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Strings in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Stringfunctionsareaccessiblebyimporting<string.h>.
●strlen()Findlengthofstring
●strcpy()Copyonestringtoother
●strcat()Jointwostrings
●strcmp()Comparetwostrings
●strlwr()Convertsstringtolowercase
●strupr()Convertsstringtouppercase
Slide 42
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Structures and Union
Slide 43
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Structures and Union
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Structuresprovidesawayforustocreateourowndatatypecalled“user-defineddatatype”
●Assumethatwehavetostorethedetailsofastudent,sowecanusestructuretostoreitasbelow:
structstudent
{
charname[10];
introllno;
floatcgpa;
};
name
rollno
cgpa
student
Structure
allocates space
for each variable
separately
Slide 44
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Structures and Union
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Unionalsoprovidesawayforustocreateourowndatatypecalled“user-defineddatatype”.
●Hereeachvariablesharesthememorycollectively.
unionstudent
{
charname[10];
introllno;
floatcgpa;
};
name
rollno
cgpa
student
Union shares the
memory
allocated for
variables
Memory
Slide 45
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Pointers in C
Slide 46
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Pointers in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
●Pointersarevariableswhichstoretheaddressofavariable.
●Theyhavedatatypejustlikevariables,forexampleanintegertypepointercanholdtheaddressof
anintegervariableandancharactertypepointercanholdtheaddressofcharvariable.
Example:
inta=20;
int*p=&a; 1001 2063
20 1001
a *p
Slide 47
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Pointers in C
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
ExampleofPointer:
#include<stdio.h>
voidmain()
{
inty=5;
int*p;
p=&y;
printf("Addressofy:%x\n",&y);
printf("Contentofp:%x\n",p);
printf("Contentof*p:%d\n",*p);
}
Slide 48
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Summary
•WesawanintroductiontoC,featuresavailableinCandtokensavailableinC.
•Then,westartedwithvariables,howtodeclareandusethem.
•Next,wecameacross,whatarethedatatypeswhichwecanusehereinClanguage.
•Thenwewentthroughtheinputandoutputfunctions,howcanweprocesstheinputanddisplay
results.
•OperatorsavailableinCthroughwhichwecanperformvariousoperationsonourdata.
•Variouscontrolsstatementssuchasif,if..else,loopsandswitchcase.
•Next,weintroducedarraysinC,howtodeclareandusethemwithexamples.
•Nextup,wesawwhatfunctionsare,howtousethemintheprogramandrecursion.
•LaterwecameacrossStrings,howtodeclareandbuilt-infunctionsavailableinstring.h.
•WeintroducedStructuresandUnionwithanexampleforeach.
•Abriefintroductiontopointers,howtodeclareandusethemwithexample.
Tags
#tages
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
8
Slides
48
Age
581 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
32 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
33 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
31 views
14
Fertility awareness methods for women in the society
Isaiah47
30 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
27 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
29 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-48)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better