SlideShare a Scribd company logo
7
Most read
10
Most read
14
Most read
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

PPTX
Array in C
adityas29
Ā 
DOC
Arrays and Strings
Dr.Subha Krishna
Ā 
PPTX
Array Of Pointers
Sharad Dubey
Ā 
PDF
Character Array and String
Tasnima Hamid
Ā 
PPT
Enumerated data types in C
Arpana shree
Ā 
PPTX
File handling in C
Kamal Acharya
Ā 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
Ā 
PPT
File handling-c
CGC Technical campus,Mohali
Ā 
Array in C
adityas29
Ā 
Arrays and Strings
Dr.Subha Krishna
Ā 
Array Of Pointers
Sharad Dubey
Ā 
Character Array and String
Tasnima Hamid
Ā 
Enumerated data types in C
Arpana shree
Ā 
File handling in C
Kamal Acharya
Ā 
Introduction to C Programming
MOHAMAD NOH AHMAD
Ā 
File handling-c
CGC Technical campus,Mohali
Ā 

What's hot (20)

PPTX
Control statements in c
Sathish Narayanan
Ā 
PPTX
Union in C programming
Kamal Acharya
Ā 
PPTX
Conditional Statement in C Language
Shaina Arora
Ā 
PPTX
Pointers in c++
sai tarlekar
Ā 
PPTX
Structure in C
Kamal Acharya
Ā 
PPTX
Array ppt
Kaushal Mehta
Ā 
PPTX
Pointer in c
lavanya marichamy
Ā 
PPTX
Pointers in c language
Tanmay Modi
Ā 
PPT
Pointers C programming
Appili Vamsi Krishna
Ā 
PPTX
Branching statements
ArunMK17
Ā 
PPTX
Strings in C
Kamal Acharya
Ā 
PPT
RECURSION IN C
v_jk
Ā 
PPTX
Arrays in Data Structure and Algorithm
KristinaBorooah
Ā 
PPT
Array in c
Ravi Gelani
Ā 
PPT
File handling in c
David Livingston J
Ā 
PPTX
data types in C programming
Harshita Yadav
Ā 
PPTX
classes and objects in C++
HalaiHansaika
Ā 
PPT
Structure of a C program
David Livingston J
Ā 
PPTX
Data types in c++
Venkata.Manish Reddy
Ā 
PPTX
Preprocessor directives in c language
tanmaymodi4
Ā 
Control statements in c
Sathish Narayanan
Ā 
Union in C programming
Kamal Acharya
Ā 
Conditional Statement in C Language
Shaina Arora
Ā 
Pointers in c++
sai tarlekar
Ā 
Structure in C
Kamal Acharya
Ā 
Array ppt
Kaushal Mehta
Ā 
Pointer in c
lavanya marichamy
Ā 
Pointers in c language
Tanmay Modi
Ā 
Pointers C programming
Appili Vamsi Krishna
Ā 
Branching statements
ArunMK17
Ā 
Strings in C
Kamal Acharya
Ā 
RECURSION IN C
v_jk
Ā 
Arrays in Data Structure and Algorithm
KristinaBorooah
Ā 
Array in c
Ravi Gelani
Ā 
File handling in c
David Livingston J
Ā 
data types in C programming
Harshita Yadav
Ā 
classes and objects in C++
HalaiHansaika
Ā 
Structure of a C program
David Livingston J
Ā 
Data types in c++
Venkata.Manish Reddy
Ā 
Preprocessor directives in c language
tanmaymodi4
Ā 
Ad

Similar to arrays and pointers (20)

PPT
Pointers on data structure in computer science.ppt
MdSabbirAhmedEkhon
Ā 
PPTX
3.ArraysandPointers.pptx
FolkAdonis
Ā 
PPTX
Mca ii dfs u-2 array records and pointer
Rai University
Ā 
PPTX
Pointers
Vardhil Patel
Ā 
DOC
Pointer
Shankar Gangaju
Ā 
PPTX
Chapter5.pptx
dhanajimirajkar1
Ā 
PPTX
C programming - Pointer and DMA
Achyut Devkota
Ā 
PPT
Arrays
swathi reddy
Ā 
PPTX
Unit 3(Arrays).pptx arrays topics in the c lang
meesalasrinuvasuraon
Ā 
PPT
Pointers definition syntax structure use
dheeraj658032
Ā 
PPT
Chapter09-10 Pointers and operations .PPT
ShalabhMishra10
Ā 
PPT
Chapter09-10.PPT
shubhamshukla9769280
Ā 
PDF
C pointers and references
Thesis Scientist Private Limited
Ā 
PPTX
Pointers and Dynamic Memory Allocation
Rabin BK
Ā 
PPT
Pointers and arrays
Bhuvana Gowtham
Ā 
PPTX
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
Ā 
PPTX
Arrays And Pointers in C programming language
Jasminelobo2
Ā 
PPTX
Pointers Notes.pptx
kartikeysaxenaco21a4
Ā 
PDF
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
Ā 
Pointers on data structure in computer science.ppt
MdSabbirAhmedEkhon
Ā 
3.ArraysandPointers.pptx
FolkAdonis
Ā 
Mca ii dfs u-2 array records and pointer
Rai University
Ā 
Pointers
Vardhil Patel
Ā 
Pointer
Shankar Gangaju
Ā 
Chapter5.pptx
dhanajimirajkar1
Ā 
C programming - Pointer and DMA
Achyut Devkota
Ā 
Arrays
swathi reddy
Ā 
Unit 3(Arrays).pptx arrays topics in the c lang
meesalasrinuvasuraon
Ā 
Pointers definition syntax structure use
dheeraj658032
Ā 
Chapter09-10 Pointers and operations .PPT
ShalabhMishra10
Ā 
Chapter09-10.PPT
shubhamshukla9769280
Ā 
C pointers and references
Thesis Scientist Private Limited
Ā 
Pointers and Dynamic Memory Allocation
Rabin BK
Ā 
Pointers and arrays
Bhuvana Gowtham
Ā 
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
Ā 
Arrays And Pointers in C programming language
Jasminelobo2
Ā 
Pointers Notes.pptx
kartikeysaxenaco21a4
Ā 
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
Ā 
Ad

Recently uploaded (20)

PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
Ā 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
PDF
Software Development Company | KodekX
KodekX
Ā 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PDF
Software Development Methodologies in 2025
KodekX
Ā 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
Ā 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
Software Development Company | KodekX
KodekX
Ā 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 

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.