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

More Related Content

What's hot (20)

Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
String functions in C
String functions in CString functions in C
String functions in C
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Structure in C
Structure in CStructure in C
Structure in C
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 

Similar to arrays and pointers

Similar to arrays and pointers (20)

C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
C language presentation
C language presentationC language presentation
C language presentation
 
Chapter09-10.PPT
Chapter09-10.PPTChapter09-10.PPT
Chapter09-10.PPT
 
Chapter09-10 Pointers and operations .PPT
Chapter09-10  Pointers and operations .PPTChapter09-10  Pointers and operations .PPT
Chapter09-10 Pointers and operations .PPT
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 
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
 
java.pdf
java.pdfjava.pdf
java.pdf
 
C language basics
C language basicsC language basics
C language basics
 
Data Handling
Data HandlingData Handling
Data Handling
 
Pointers
PointersPointers
Pointers
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
C language
C languageC language
C language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 

Recently uploaded

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 

Recently uploaded (20)

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 

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.