SlideShare a Scribd company logo
ARRAY, STRING AND
POINTER
Unit 3
ARRAY
An array is a sequential collection of variables
of same data type which can be accessed using
an integer as index, that generally starts from
0. It stores data elements in a continuous
memory location. Each element can be
individually referenced with its respective
index.
…
1-Dimensional array: It is a linear array that stores
elements in a sequential order. Let us try to
demonstrate this with an example: Let us say we have
to store integers 2, 3, 5, 4, 6, 7. We can store it in an
array of integer data type. The way to do it is:
Declaration:
dataType nameOfTheArray [sizeOfTheArray];
int Arr[6];
Here Arr is the name of array and 6 is the size. It is necessary to define
the size array at compile time.
…
To store the above elements in the array:
dataType nameOfTheArray [ ] = {elements of array };
int Arr [ ] = { 2, 3, 5, 4, 6, 7 };
Since, the indexing of
an array starts from 0,
if the 4th element
needs to be accessed,
Arr [ 3 ] will give you
the value of the 4th
element. Similarly, nth
element can be
accessed by Arr[n-1].
…
#include<stdio.h>
int main(void)
{
int a[5];
a[0]=9;
a[1]=10;
a[2]=14;
a[3]=76;
a[4]=34;
for(int i=0; i<5;
i++)
{
printf("%d",a[i]);
}
#include<stdio.h>
int main(void)
{
int
a[5]={9,4,22,18,17};
for(int i=0; i<5; i++)
{
printf("%d",a[i]);
}
}
…
#include<stdio.h>
int main(void)
{
int a[5];
printf("Enter the 5 values:
");
for(int i=0; i<5; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<5; i++)
{
printf("nThe Values are:
%d",a[i]);
}
WHY ARRAY STARTS FROM ‘0’
5000 + 0 (Index) * 2(Size of Datatype
INT)
= 5000
5000 + 1 (Index) * 2(Size of Datatype
INT)
= 5002
5000 + 2 (Index) * 2(Size of Datatype
INT)
= 5004
5000 + 0 (Index) * 4(Size of Datatype
Float)
= 5000
5000 + 1 (Index) * 4(Size of Datatype
Float)
= 5004
5000 + 2 (Index) * 4(Size of Datatype = 5008
For INT Data Type
For FLOAT Data Type
STRING
STRING
In C, string is stored in an array of characters.
Each character in a string occupies one location in an
array. The null character '0' is put after the last character.
This is done so that program can tell when the end of
the string has been reached.
char c[] = “any name";
When the compiler encounters a sequence of characters
enclosed in the double quotation marks, it appends a null
character 0 at the end by default.
DECLARATION
char s[5];
Here, we have declared a string of 5 characters.
Initialization
char c[] = "abcd";
char c[50] = "abcd";
char c[] = {'a', 'b', 'c', 'd', '0'};
char c[5] = {'a', 'b', 'c', 'd', '0'};
EXAMPLE
#include <stdio.h>
void main ()
{
char a[7] = { ‘e’, ‘x’, ‘a’, ‘m’, ‘p’, ‘l’, ’e’ };
char b[10];
printf (“Enter the value for B”);
scanf("%s",b);
printf ("A Output: %sn", a);
printf ("B Output: %sn", b);
}
STRING FUNCTIONS
1. strlen("name of string")
2. strcpy( dest, source)
3. strcmp( string1, string2 )
4. strstr( str1, str2 )
STRING COPY AND LENGTH
#include <stdio.h>
#include <string.h>
Int main ()
{
char a[7] = { 'n', 'i', 's', 'h', 'a', 'n' };
char b[10]; int c; //scanf("%s",a);
printf ("A Output: %sn", a);
strcpy(b, a); c=strlen(b);
printf ("B Output: %sn", b);
printf ("B Output: %dn", c);
return 0;
}
STRCMP( STR1 , STR2 );
This function is used to compare two strings "str1"
and "str2". this function returns zero("0") if the two
compared strings are equal, else some none zero
integer.
Return value
- if Return value if < 0 then it indicates str1 is less
than str2
- if Return value if > 0 then it indicates str2 is less
than str1
- if Return value if = 0 then it indicates str1 is equal to
str2
#include <stdio.h>
#include <string.h>
void main ()
{
char a[10];
char b[10];
int c;
printf ("nEnter the value for a: ");
scanf("%s",a);
printf ("nEnter the value for b: ");
scanf("%s",b);
if(strcmp(b, a)==0)
{
printf ("Strings are equal");
}
else
{
printf ("Strings are not equal");
}
}
Output:
Enter the value of a:
example
Enter the value of b:
example
Strings are equal.
STRSTR()
#include<stdio.h>
#include<string.h>
int main ()
{
char str1[55] ="This is a test string for testing";
char str2[20]="test";
char *p;
p = strstr (str1, str2);
if(p)
{
printf("string foundn" );
}
else printf("string not foundn" );
return 0;
}
Output:
String found
POINTER
POINTERS
Pointers store address of variables or a memory
location.
datatype *var_name;
int *ptr;
// An example pointer "ptr" that holds address of an integer variable
or holds address of a memory whose value(s) can be accessed as
integer values through "ptr"
…
#include <stdio.h>
void main()
{
int x = 10;
int *ptr;
ptr = &x;
printf(“Value is : %d”,*ptr);
}
1) Since there is * in declaration, ptr
becomes a pointer varaible (a variable
that stores address of another variable)
2) Since there is int before *, ptr is
pointer to an integer type variable int
*ptr;& operator before x is used to get
address of x. The address of x is
assigned to ptr.
…
void main()
{
int *p;
int var = 10;
p= &var;
printf("Value of variable var is: %d", var);
printf("nValue of variable var is: %d",
*p);
printf("nAddress of variable var is: %d",
&var);
printf("nAddress of variable var is: %d",
p);
/* Pointer of integer type, this can hold
the * address of a integer type variable.
*/
/* Assigning the address of variable var to
the pointer * p. The p can hold the
address of var because var is * an integer
type variable. */
Output:
Value of variable var is: 10
Value of variable var is: 10
Address of variable var is: 0x7fff5ed98c4c
Address of variable var is: 0x7fff5ed98c4c
Address of pointer p is: 0x7fff5ed98c50
…
ASCII VALUES
1. The ASCII table has 128
characters, with values from
0 through 127.
2. Uppercase A has ASCII
value 65 in decimal .So
for Z ,the value is 90 in
decimal.
3. Lowercase a has ASCII
value 97 in decimal .So
for z ,the value is 122 in
decimal.
The following program gives the ASCII values :
#include <stdio.h>
int main()
{
int i;
for( i=0 ; i<=255 ; i++ ) /*ASCII values ranges
from 0-255*/
{
printf("ASCII value of character %d = %cn", i, i);
}
}

More Related Content

What's hot (20)

Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
Frankie Jones
 
Array
ArrayArray
Array
Hajar
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
strings
stringsstrings
strings
teach4uin
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
Md. Imran Hossain Showrov
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
Md. Imran Hossain Showrov
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
Rubal Bansal
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Appili Vamsi Krishna
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Arrays
ArraysArrays
Arrays
Shakila Mahjabin
 
Strings
StringsStrings
Strings
Saranya saran
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
tanmaymodi4
 
Ponters
PontersPonters
Ponters
Mukund Trivedi
 
Arrays
ArraysArrays
Arrays
Rahul Mahamuni
 

Similar to Array, string and pointer (20)

4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
Chhom Karath
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Unit 2
Unit 2Unit 2
Unit 2
TPLatchoumi
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
Keypoints c strings
Keypoints   c stringsKeypoints   c strings
Keypoints c strings
Akila Krishnamoorthy
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
Sitamarhi Institute of Technology
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
Dushmanta Nath
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
MohammadSalman129
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
UNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c languageUNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c language
wwwskrilikeyou
 
Slide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdfSlide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdf
HimanshuKansal22
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Ponters
PontersPonters
Ponters
Anil Dutt
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
Saad Sheikh
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Lesson in Strings for C Programming Lessons
Lesson in Strings for C Programming LessonsLesson in Strings for C Programming Lessons
Lesson in Strings for C Programming Lessons
JamesChristianGadian
 
string function with example...................
string function with example...................string function with example...................
string function with example...................
NishantsrivastavaV
 
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...PPS 4.4ARRAYS  ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
PPS 4.4ARRAYS ARRAY DECLARATION & INITIALIZATION, BOUND CHECKING ARRAYS (1-D...
Sitamarhi Institute of Technology
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
Dushmanta Nath
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
MohammadSalman129
 
ARRAY's in C Programming Language PPTX.
ARRAY's in C  Programming Language PPTX.ARRAY's in C  Programming Language PPTX.
ARRAY's in C Programming Language PPTX.
MSridhar18
 
UNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c languageUNIT 4 POINTERS.pptx pointers pptx for basic c language
UNIT 4 POINTERS.pptx pointers pptx for basic c language
wwwskrilikeyou
 
Slide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdfSlide set 6 Strings and pointers.pdf
Slide set 6 Strings and pointers.pdf
HimanshuKansal22
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
AntareepMajumder
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
Saad Sheikh
 
Ad

More from Nishant Munjal (20)

Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant Munjal
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
Nishant Munjal
 
Programming in C
Programming in CProgramming in C
Programming in C
Nishant Munjal
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
Nishant Munjal
 
Unix Administration
Unix AdministrationUnix Administration
Unix Administration
Nishant Munjal
 
Shell Programming Concept
Shell Programming ConceptShell Programming Concept
Shell Programming Concept
Nishant Munjal
 
VI Editor
VI EditorVI Editor
VI Editor
Nishant Munjal
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
Nishant Munjal
 
Routing Techniques
Routing TechniquesRouting Techniques
Routing Techniques
Nishant Munjal
 
Asynchronous Transfer Mode
Asynchronous Transfer ModeAsynchronous Transfer Mode
Asynchronous Transfer Mode
Nishant Munjal
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud Computing
Nishant Munjal
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
Nishant Munjal
 
Concurrency Control
Concurrency ControlConcurrency Control
Concurrency Control
Nishant Munjal
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
Nishant Munjal
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant Munjal
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
Virtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudVirtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of Cloud
Nishant Munjal
 
Technical education benchmarks
Technical education benchmarksTechnical education benchmarks
Technical education benchmarks
Nishant Munjal
 
Bluemix Introduction
Bluemix IntroductionBluemix Introduction
Bluemix Introduction
Nishant Munjal
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant Munjal
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
Nishant Munjal
 
Shell Programming Concept
Shell Programming ConceptShell Programming Concept
Shell Programming Concept
Nishant Munjal
 
Asynchronous Transfer Mode
Asynchronous Transfer ModeAsynchronous Transfer Mode
Asynchronous Transfer Mode
Nishant Munjal
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud Computing
Nishant Munjal
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
Nishant Munjal
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
Nishant Munjal
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
Nishant Munjal
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Nishant Munjal
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
Virtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudVirtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of Cloud
Nishant Munjal
 
Technical education benchmarks
Technical education benchmarksTechnical education benchmarks
Technical education benchmarks
Nishant Munjal
 
Ad

Recently uploaded (20)

Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
Impurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptxImpurities of Water and their Significance.pptx
Impurities of Water and their Significance.pptx
dhanashree78
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
A DECISION SUPPORT SYSTEM FOR ESTIMATING COST OF SOFTWARE PROJECTS USING A HY...
ijfcstjournal
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSWIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODS
samueljackson3773
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt3. What is the principles of Teamwork_Module_V1.0.ppt
3. What is the principles of Teamwork_Module_V1.0.ppt
engaash9
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 

Array, string and pointer

  • 2. ARRAY An array is a sequential collection of variables of same data type which can be accessed using an integer as index, that generally starts from 0. It stores data elements in a continuous memory location. Each element can be individually referenced with its respective index.
  • 3. … 1-Dimensional array: It is a linear array that stores elements in a sequential order. Let us try to demonstrate this with an example: Let us say we have to store integers 2, 3, 5, 4, 6, 7. We can store it in an array of integer data type. The way to do it is: Declaration: dataType nameOfTheArray [sizeOfTheArray]; int Arr[6]; Here Arr is the name of array and 6 is the size. It is necessary to define the size array at compile time.
  • 4. … To store the above elements in the array: dataType nameOfTheArray [ ] = {elements of array }; int Arr [ ] = { 2, 3, 5, 4, 6, 7 }; Since, the indexing of an array starts from 0, if the 4th element needs to be accessed, Arr [ 3 ] will give you the value of the 4th element. Similarly, nth element can be accessed by Arr[n-1].
  • 5. … #include<stdio.h> int main(void) { int a[5]; a[0]=9; a[1]=10; a[2]=14; a[3]=76; a[4]=34; for(int i=0; i<5; i++) { printf("%d",a[i]); } #include<stdio.h> int main(void) { int a[5]={9,4,22,18,17}; for(int i=0; i<5; i++) { printf("%d",a[i]); } }
  • 6. … #include<stdio.h> int main(void) { int a[5]; printf("Enter the 5 values: "); for(int i=0; i<5; i++) { scanf("%d",&a[i]); } for(i=0; i<5; i++) { printf("nThe Values are: %d",a[i]); }
  • 7. WHY ARRAY STARTS FROM ‘0’ 5000 + 0 (Index) * 2(Size of Datatype INT) = 5000 5000 + 1 (Index) * 2(Size of Datatype INT) = 5002 5000 + 2 (Index) * 2(Size of Datatype INT) = 5004 5000 + 0 (Index) * 4(Size of Datatype Float) = 5000 5000 + 1 (Index) * 4(Size of Datatype Float) = 5004 5000 + 2 (Index) * 4(Size of Datatype = 5008 For INT Data Type For FLOAT Data Type
  • 9. STRING In C, string is stored in an array of characters. Each character in a string occupies one location in an array. The null character '0' is put after the last character. This is done so that program can tell when the end of the string has been reached. char c[] = “any name"; When the compiler encounters a sequence of characters enclosed in the double quotation marks, it appends a null character 0 at the end by default.
  • 10. DECLARATION char s[5]; Here, we have declared a string of 5 characters. Initialization char c[] = "abcd"; char c[50] = "abcd"; char c[] = {'a', 'b', 'c', 'd', '0'}; char c[5] = {'a', 'b', 'c', 'd', '0'};
  • 11. EXAMPLE #include <stdio.h> void main () { char a[7] = { ‘e’, ‘x’, ‘a’, ‘m’, ‘p’, ‘l’, ’e’ }; char b[10]; printf (“Enter the value for B”); scanf("%s",b); printf ("A Output: %sn", a); printf ("B Output: %sn", b); }
  • 12. STRING FUNCTIONS 1. strlen("name of string") 2. strcpy( dest, source) 3. strcmp( string1, string2 ) 4. strstr( str1, str2 )
  • 13. STRING COPY AND LENGTH #include <stdio.h> #include <string.h> Int main () { char a[7] = { 'n', 'i', 's', 'h', 'a', 'n' }; char b[10]; int c; //scanf("%s",a); printf ("A Output: %sn", a); strcpy(b, a); c=strlen(b); printf ("B Output: %sn", b); printf ("B Output: %dn", c); return 0; }
  • 14. STRCMP( STR1 , STR2 ); This function is used to compare two strings "str1" and "str2". this function returns zero("0") if the two compared strings are equal, else some none zero integer. Return value - if Return value if < 0 then it indicates str1 is less than str2 - if Return value if > 0 then it indicates str2 is less than str1 - if Return value if = 0 then it indicates str1 is equal to str2
  • 15. #include <stdio.h> #include <string.h> void main () { char a[10]; char b[10]; int c; printf ("nEnter the value for a: "); scanf("%s",a); printf ("nEnter the value for b: "); scanf("%s",b); if(strcmp(b, a)==0) { printf ("Strings are equal"); } else { printf ("Strings are not equal"); } } Output: Enter the value of a: example Enter the value of b: example Strings are equal.
  • 16. STRSTR() #include<stdio.h> #include<string.h> int main () { char str1[55] ="This is a test string for testing"; char str2[20]="test"; char *p; p = strstr (str1, str2); if(p) { printf("string foundn" ); } else printf("string not foundn" ); return 0; } Output: String found
  • 18. POINTERS Pointers store address of variables or a memory location. datatype *var_name; int *ptr; // An example pointer "ptr" that holds address of an integer variable or holds address of a memory whose value(s) can be accessed as integer values through "ptr"
  • 19. … #include <stdio.h> void main() { int x = 10; int *ptr; ptr = &x; printf(“Value is : %d”,*ptr); } 1) Since there is * in declaration, ptr becomes a pointer varaible (a variable that stores address of another variable) 2) Since there is int before *, ptr is pointer to an integer type variable int *ptr;& operator before x is used to get address of x. The address of x is assigned to ptr.
  • 20. … void main() { int *p; int var = 10; p= &var; printf("Value of variable var is: %d", var); printf("nValue of variable var is: %d", *p); printf("nAddress of variable var is: %d", &var); printf("nAddress of variable var is: %d", p); /* Pointer of integer type, this can hold the * address of a integer type variable. */ /* Assigning the address of variable var to the pointer * p. The p can hold the address of var because var is * an integer type variable. */ Output: Value of variable var is: 10 Value of variable var is: 10 Address of variable var is: 0x7fff5ed98c4c Address of variable var is: 0x7fff5ed98c4c Address of pointer p is: 0x7fff5ed98c50
  • 21.
  • 22. ASCII VALUES 1. The ASCII table has 128 characters, with values from 0 through 127. 2. Uppercase A has ASCII value 65 in decimal .So for Z ,the value is 90 in decimal. 3. Lowercase a has ASCII value 97 in decimal .So for z ,the value is 122 in decimal. The following program gives the ASCII values : #include <stdio.h> int main() { int i; for( i=0 ; i<=255 ; i++ ) /*ASCII values ranges from 0-255*/ { printf("ASCII value of character %d = %cn", i, i); } }