SlideShare a Scribd company logo
C Programming
Fundamentals
CONTENTS
 Variables
 Placeholders
 Arrays
 Pointers
 Types of Pointers
 Arrays using Pointers
• Variables are simply names used to refer to some location in memory
– a location that holds a value with which we are working.
• Variable names may consists of letters, digits, and the underscore
character subject to the following conditions.
• Eg:- avg,
count ,
emp_salary ,
num1, etc.
Variables
Rules of declaring Variables
• Commas or blanks are not allowed.
• No special characters allowed.
• First letter of the variable should be a letter.
• Uppercase and lowercase letters are significant.
• Variable name should not be a C keyword.
• It should not have same name as the function thst is written by
the user or already exist in the C library.
• Each variable used must be declared in the program.
Placeholders
Placeholders are used to determine when what type of values are going
to be input or displayed, depending on what type of functions that we
use.
Data type Placeholder
int %d
Char %c
float %f
string %s
Input Placeholders:
scanf() function requires input placeholders to allow data to be
transferred to the specific variable depending on which placeholder
we will use.
Output Placeholders:
Output placeholders are used to display data onto the screen. printf()
function uses the output placeholder when necessary. The only
difference with the input placeholders is the double data type
placeholder for input function is %lf, while the double data type
placeholder for output function is %f.
Arrays
 An array is fixed size sequential collection of elements of
homogenous nature.
 Array Declaration:- data_type arrayname[size];
eg- int arr[20]; /*defines a block of 20 consecutive objects of
type int */
 Array Initialization:- int a[5] = { 1,2,3,4,5};
int a[ ] = {1,2,3,4,5};
 Types:- One dimensional
Multi dimensional
One Dimensional Arrays
 A collection of variables are given one variable name using only one
subscript and such a variable is called a single-subscripted variable or
one dimensional array.
 Syntax:- data_type ArrayName[size];
data_type: is a valid data type like int, char, or float.
ArrayName: is a valid identifier.
Size: maximum no. of elements that can be stored in an array.
 Initialization:- int arr[5];
 Stored in contiguous memory locations.
Multi Dimensional Arrays
Two dimensional Array:
 Syntax: data_type ArrayName[rowsize][columnsize];
data_type: is a valid data type like int, char, or float.
ArrayName: is a valid identifier.
rowsize and columnsize : maximum no. of elements that can
be stored in the row and the column.
Initialization:- int arr[2][2];
int arr[2][2] = {1,2,0,1};
int arr[3][3] = {{1,2,0},{1,4,6},{3,8,3}};
Pointers
 A pointer variable is another variable that holds the address of
the given variable to be accessed. Pointers provide a way of
accessing a variable without referring to variable directly.
 Declaration:- type ∗pt_name;
Initialization:- int x, ∗p = & x;
 A pointer should be initialized before use.
 The unary operator ∗ is termed as dereference operator or
indirection operator, as it allows to access the value of a variable
indirectly.
Types Of Pointers
• Null Pointer :- Null pointer is a constant with a value of zero
defined in several standard libraries.
Eg:- int *ptr = NULL
• Dangling Pointers :- If any pointer is pointing to any address at
given point in a program and later on the variable has been
deleted from that specific memory location, although the pointer
is still referring to the memory location. These pointers are called
dangling pointers.
Eg :- int *x,* y;
x = (int *)malloc(sizeof (int));
*y=10;
x = y;
free (y);
• GenericPointers :- Pointers which doesn’t have any specific data
type is known as generic pointers.
Eg :- void *the_data;
• Wild Pointers :- Uninitialized pointers are known as wild
pointers because they point to some arbitrary memory location
and may cause a program to crash or behave badly.
Eg:- int main ( )
{
int *ptr;
printf(“%d”,*ptr);
}
#include <stdio.h>
int main()
{
int data[5], i;
printf("Enter elements: ");
for(i = 0; i < 5; ++i)
scanf("%d", data + i);
printf("You entered: n");
for(i = 0; i < 5; ++i)
printf("%dn", *(data + i));
return 0;
}
Arrays Using Pointers
Output :
Enter elements: 1
2
3
5
4
You entered: 1
2
3
5
4
Difference between Arrays and
Pointers
POINTERS
ARRAY
Pointer is a variable which stores
the address of another variable.
Array is a collectihon of
homogeneous data elements.
Pointer can’t be initialized at
definition.
Arrays can be initialized at
definition.
They are static in nature. They are static in nature.
The assembly code of pointer is
different that array.
The assembly code of an array is
different than pointer.
THANK YOU
Ad

More Related Content

What's hot (20)

Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
Kamal Acharya
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
Nitesh Kumar Pandey
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
structure and union
structure and unionstructure and union
structure and union
student
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 
C pointer
C pointerC pointer
C pointer
University of Potsdam
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
C tokens
C tokensC tokens
C tokens
Manu1325
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
tanmaymodi4
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 

Similar to arrays and pointers (20)

C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Unit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c langUnit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c lang
meesalasrinuvasuraon
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFPROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
C language presentation
C language presentationC language presentation
C language presentation
bainspreet
 
Pointers definition syntax structure use
Pointers definition syntax structure usePointers definition syntax structure use
Pointers definition syntax structure use
dheeraj658032
 
Chapter09-10 Pointers and operations .PPT
Chapter09-10  Pointers and operations .PPTChapter09-10  Pointers and operations .PPT
Chapter09-10 Pointers and operations .PPT
ShalabhMishra10
 
Chapter09-10.PPT
Chapter09-10.PPTChapter09-10.PPT
Chapter09-10.PPT
shubhamshukla9769280
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
valarpink
 
Lesson 7-computer programming case study-FINAL.pptx
Lesson 7-computer programming case study-FINAL.pptxLesson 7-computer programming case study-FINAL.pptx
Lesson 7-computer programming case study-FINAL.pptx
claritoBaluyot2
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
sanjanaMudduluru1
 
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt  BASIC WITH DEPTH CONTENTlecture-ON-C.ppt  BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
NagarathnaRajur2
 
basic of C programming (token, keywords)lecture2.ppt
basic of C programming (token, keywords)lecture2.pptbasic of C programming (token, keywords)lecture2.ppt
basic of C programming (token, keywords)lecture2.ppt
Raglandroyal1
 
lecture2.ppt...............................................
lecture2.ppt...............................................lecture2.ppt...............................................
lecture2.ppt...............................................
taywadebhagyashree2
 
data types in c programming language in detail
data types in c programming language in detaildata types in c programming language in detail
data types in c programming language in detail
atulk4360
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
java.pdf
java.pdfjava.pdf
java.pdf
RAJCHATTERJEE24
 
C language basics
C language basicsC language basics
C language basics
Nikshithas R
 
Data Handling
Data HandlingData Handling
Data Handling
Praveen M Jigajinni
 
Unit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c langUnit 3(Arrays).pptx arrays topics in the c lang
Unit 3(Arrays).pptx arrays topics in the c lang
meesalasrinuvasuraon
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFPROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
C language presentation
C language presentationC language presentation
C language presentation
bainspreet
 
Pointers definition syntax structure use
Pointers definition syntax structure usePointers definition syntax structure use
Pointers definition syntax structure use
dheeraj658032
 
Chapter09-10 Pointers and operations .PPT
Chapter09-10  Pointers and operations .PPTChapter09-10  Pointers and operations .PPT
Chapter09-10 Pointers and operations .PPT
ShalabhMishra10
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
valarpink
 
Lesson 7-computer programming case study-FINAL.pptx
Lesson 7-computer programming case study-FINAL.pptxLesson 7-computer programming case study-FINAL.pptx
Lesson 7-computer programming case study-FINAL.pptx
claritoBaluyot2
 
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt  BASIC WITH DEPTH CONTENTlecture-ON-C.ppt  BASIC WITH DEPTH CONTENT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
NagarathnaRajur2
 
basic of C programming (token, keywords)lecture2.ppt
basic of C programming (token, keywords)lecture2.pptbasic of C programming (token, keywords)lecture2.ppt
basic of C programming (token, keywords)lecture2.ppt
Raglandroyal1
 
lecture2.ppt...............................................
lecture2.ppt...............................................lecture2.ppt...............................................
lecture2.ppt...............................................
taywadebhagyashree2
 
data types in c programming language in detail
data types in c programming language in detaildata types in c programming language in detail
data types in c programming language in detail
atulk4360
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Ad

Recently uploaded (20)

AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Ad

arrays and pointers

  • 2. CONTENTS  Variables  Placeholders  Arrays  Pointers  Types of Pointers  Arrays using Pointers
  • 3. • Variables are simply names used to refer to some location in memory – a location that holds a value with which we are working. • Variable names may consists of letters, digits, and the underscore character subject to the following conditions. • Eg:- avg, count , emp_salary , num1, etc. Variables
  • 4. Rules of declaring Variables • Commas or blanks are not allowed. • No special characters allowed. • First letter of the variable should be a letter. • Uppercase and lowercase letters are significant. • Variable name should not be a C keyword. • It should not have same name as the function thst is written by the user or already exist in the C library. • Each variable used must be declared in the program.
  • 5. Placeholders Placeholders are used to determine when what type of values are going to be input or displayed, depending on what type of functions that we use. Data type Placeholder int %d Char %c float %f string %s
  • 6. Input Placeholders: scanf() function requires input placeholders to allow data to be transferred to the specific variable depending on which placeholder we will use. Output Placeholders: Output placeholders are used to display data onto the screen. printf() function uses the output placeholder when necessary. The only difference with the input placeholders is the double data type placeholder for input function is %lf, while the double data type placeholder for output function is %f.
  • 7. Arrays  An array is fixed size sequential collection of elements of homogenous nature.  Array Declaration:- data_type arrayname[size]; eg- int arr[20]; /*defines a block of 20 consecutive objects of type int */  Array Initialization:- int a[5] = { 1,2,3,4,5}; int a[ ] = {1,2,3,4,5};  Types:- One dimensional Multi dimensional
  • 8. One Dimensional Arrays  A collection of variables are given one variable name using only one subscript and such a variable is called a single-subscripted variable or one dimensional array.  Syntax:- data_type ArrayName[size]; data_type: is a valid data type like int, char, or float. ArrayName: is a valid identifier. Size: maximum no. of elements that can be stored in an array.  Initialization:- int arr[5];  Stored in contiguous memory locations.
  • 9. Multi Dimensional Arrays Two dimensional Array:  Syntax: data_type ArrayName[rowsize][columnsize]; data_type: is a valid data type like int, char, or float. ArrayName: is a valid identifier. rowsize and columnsize : maximum no. of elements that can be stored in the row and the column. Initialization:- int arr[2][2]; int arr[2][2] = {1,2,0,1}; int arr[3][3] = {{1,2,0},{1,4,6},{3,8,3}};
  • 10. Pointers  A pointer variable is another variable that holds the address of the given variable to be accessed. Pointers provide a way of accessing a variable without referring to variable directly.  Declaration:- type ∗pt_name; Initialization:- int x, ∗p = & x;  A pointer should be initialized before use.  The unary operator ∗ is termed as dereference operator or indirection operator, as it allows to access the value of a variable indirectly.
  • 11. Types Of Pointers • Null Pointer :- Null pointer is a constant with a value of zero defined in several standard libraries. Eg:- int *ptr = NULL • Dangling Pointers :- If any pointer is pointing to any address at given point in a program and later on the variable has been deleted from that specific memory location, although the pointer is still referring to the memory location. These pointers are called dangling pointers. Eg :- int *x,* y; x = (int *)malloc(sizeof (int)); *y=10; x = y; free (y);
  • 12. • GenericPointers :- Pointers which doesn’t have any specific data type is known as generic pointers. Eg :- void *the_data; • Wild Pointers :- Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave badly. Eg:- int main ( ) { int *ptr; printf(“%d”,*ptr); }
  • 13. #include <stdio.h> int main() { int data[5], i; printf("Enter elements: "); for(i = 0; i < 5; ++i) scanf("%d", data + i); printf("You entered: n"); for(i = 0; i < 5; ++i) printf("%dn", *(data + i)); return 0; } Arrays Using Pointers Output : Enter elements: 1 2 3 5 4 You entered: 1 2 3 5 4
  • 14. Difference between Arrays and Pointers POINTERS ARRAY Pointer is a variable which stores the address of another variable. Array is a collectihon of homogeneous data elements. Pointer can’t be initialized at definition. Arrays can be initialized at definition. They are static in nature. They are static in nature. The assembly code of pointer is different that array. The assembly code of an array is different than pointer.