SlideShare a Scribd company logo
C
PROGRAMMIN
GUNIT-3
ARRAY
Introduction to
Array:
What is an Array?
An array in C is a collection of similar data types stored in contiguous memory locations. It's
a fundamental data structure used to store multiple values under a single name.
Declaring an Array
To declare an array, you specify the data type, array name, and size:
Syntax:
data_type array_name[size];
Example:
int numbers[5];
One Dimentional
Array:
A one-dimensional array is a linear collection of elements of the same data type, stored in
contiguous memory locations. It's like a row of containers, each holding a value of the same
type.
Declaring a One-Dimensional Array
Syntax:
data_type array_name[size];
• data_type: The data type of the elements (e.g., int, float, char).
• array_name: The name of the array.
• size: The number of elements in the array.
Accessing Array Elements:
To access an element, use its index within square brackets:
Syntax:
array_name[index]
• index: The position of the element (starts from 0).
Example:
numbers[2] = 30;
Initializing an Array:
You can initialize an array while declaring it:
Syntax:
data_type array_name[size] = {value1, value2, ..., valueN};
Example:
int marks[5] = {85, 92, 78, 95, 88};
Example Program for one dimentional array:
#include <stdio.h>
int main() {
int numbers[5] = {2, 4, 6, 8, 10};
int i;
// Accessing and printing array elements
for (i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
return 0;
}
Two Dimentional
Array:
Declaring a Two-Dimensional Array
syntax:
data_type array_name[rows][columns];
Example:
int matrix[3][4];
A two-dimensional array is essentially an array of arrays. It can be visualized as a matrix with
rows and columns. Each element in the array is identified by two indices: one for the row and
one for the column.
Accessing Array Elements:
To access an element, use two indices:
Syntax:
array_name[row][column];
Example:
matrix[1][2] = 10;
Initializing a Two-Dimensional Array
You can initialize a two-dimensional array while declaring it:
Syntax:
data_type array_name[rows][columns] = {{value11, value12, ...},
{value21, value22, ...},
...};
Example:
int numbers[2][3] = {{1, 2, 3}, {4, 5, 6}};
Example Program
#include <stdio.h>
int main() {
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int i, j;
// Accessing and printing array elements
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", matrix[i][j]);
}
printf("n");
}
return 0;
}
Multidimensional
Array:
A multidimensional array is an extension of the concept of a one-dimensional array. It's essentially
an array of arrays, allowing you to store data in a tabular or grid-like structure.
Declaring a Multidimensional Array:
Syntax:
data_type array_name[size1][size2][...][sizeN];
Example:
int matrix[3][4];
Accessing Array Elements
To access an element, use multiple indices separated by commas:
Syntax:
array_name[index1][index2][...][indexN]
Example:
matrix[1][2] = 10;
Initializing a Multidimensional Array
You can initialize a multidimensional array while declaring it:
Syntax:
data_type array_name[size1][size2] = {{value11, value12, ...},
{value21, value22, ...},
Example:
int numbers[2][3] = {{1, 2, 3}, {4, 5, 6}};
...};
Example Program (3D Array)
#include <stdio.h>
int main() {
int cube[2][3][2] = {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}};
int i, j, k;
// Accessing and printing array elements
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 2; k++) {
printf("%d ", cube[i][j][k]);
}
printf("n");
}
printf("n");
}
return 0;
}
Character Array and
String:
Character Arrays
A character array in C is simply an array of characters. It's a fundamental building block for
handling text data.
Declaration:
char char_array[size];
• size: The maximum number of characters the array can hold.
Example:
char message[10] = "Hello";
String:
Strings
In C, a string is essentially a character array with a null character ('0') at the end to mark its
termination. This allows functions to determine the length of the string without explicitly
storing it.
Key points:
• Strings are implicitly null-terminated.
• You can use string manipulation functions from the string.h library.
Example:
char greeting[] = "Welcome";
Initializing String Variables in C
In C, strings are essentially character arrays with a null terminator (0) at the end. There are
primarily two methods to initialize a string variable:
1. Direct Initialization
Example:
char str[] = "Hello, world!"
2. Explicit Initialization
Example:
char str[14] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '0'};
Example:
#include <stdio.h>
int main() {
char str1[] = "Hello";
char str2[6] = {'W', 'o', 'r', 'l', 'd', '0'};
printf("%s %sn", str1, str2);
return 0;
}
Reading Strings from the Terminal:
Using scanf()
The scanf() function can be used to read a string from the standard input (terminal). However,
it has limitations: it stops reading at the first whitespace character (space, tab, newline).
Example:
#include <stdio.h>
int main() {
char str[100];
printf("Enter a string: ");
scanf("%s", str);
printf("You entered: %sn", str);
return 0;
}
Using fgets()
The fgets() function is a safer and more flexible way to read a string, including whitespace
characters. It reads a specified number of characters or until a newline character is
encountered.
Example:
#include <stdio.h>
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, 100, stdin);
printf("You entered: %s", str);
return 0;
}
Writing String to Screen:
Using printf()
The most common way to write a string to the screen in C is using the printf() function.
Example:
#include <stdio.h>int main() {
char str[] = "Hello, world!";
printf("%sn", str);
return 0;
}
Using puts()
Another option is the puts() function, which is specifically designed for writing strings to the standard output.
Example:
#include <stdio.h>int main() {
char str[] = "Hello, world!";
puts(str);
return 0;
}
Comparing Strings in C
Using the strcmp() Function
The most common and efficient way to compare strings in C is by using the strcmp() function
from the string.h library.
Syntax:
int strcmp(const char *str1, const char *str2);
Manual String Comparison
While strcmp() is generally preferred, you can also compare strings manually by iterating
through characters and comparing them individually. This approach can be useful for specific
scenarios or learning purposes.
Example Program:
#include <stdio.h>
int compare_strings(const char *str1, const char *str2) {
while (*str1 != '0' && *str2 != '0') {
if (*str1 != *str2) {
return *str1 - *str2; // Return difference in ASCII values
}
str1++;
str2++;
}
return *str1 - *str2; // Compare lengths if strings are equal up to this point
}
int main() {
char str1[] = "hello";
char str2[] = "world";
int result = compare_strings(str1, str2);
if (result == 0) {
printf("Strings are equaln");
} else {
printf("Strings are not equaln");
}
return 0;
}
String Handling Functions in C
C provides a rich set of functions for manipulating strings. These functions are primarily
defined in the string.h header file.
Common String Handling Functions
Here are some of the most commonly used string handling functions in C:
Length of a String
• strlen(str): Returns the length of a string (excluding the null terminator).
Copying Strings
• strcpy(dest, src): Copies the string src to the destination string dest. Be cautious about
buffer overflows.
• strncpy(dest, src, n): Copies at most n characters from src to dest.
Concatenating Strings
• strcat(dest, src): Appends src to the end of dest. Be careful about buffer overflows.
• strncat(dest, src, n): Appends at most n characters from src to dest.
Comparing Strings
• strcmp(str1, str2): Compares two strings lexicographically. Returns 0 if equal, a negative value
if str1 is less than str2, and a positive value if str1 is greater than str2.
• strncmp(str1, str2, n): Compares at most n characters of str1 and str2.
Searching in Strings
• strchr(str, ch): Finds the first occurrence of character ch in string str.
• strrchr(str, ch): Finds the last occurrence of character ch in string str.
• strstr(str1, str2): Finds the first occurrence of string str2 in string str1.
Converting Case
• tolower(ch): Converts a character to lowercase.
• toupper(ch): Converts a character to uppercase.
Other Useful Functions
• strtok(str, delimiters): Breaks a string into tokens based on delimiters.
• memset(str, ch, n): Fills a block of memory with a specific character.
• memcpy(dest, src, n): Copies a block of memory from src to dest.
Example Program
#include <stdio.h>#include <string.h>int main() {
char str1[] = "hello";
char str2[20];
strcpy(str2, str1);
strcat(str2, " world");
printf("%sn", str2);
if (strcmp(str1, "hello") == 0) {
printf("Strings are equaln");
}
char *ptr = strchr(str2, 'o');
if (ptr) {
printf("First occurrence of 'o': %sn", ptr);
}
return 0;
}
THANK YOU
Search . . .

More Related Content

Similar to ARRAY's in C Programming Language PPTX. (20)

C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptxMODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
lomic31750
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
c unit programming arrays in detail 3.pptx
c unit programming arrays in detail 3.pptxc unit programming arrays in detail 3.pptx
c unit programming arrays in detail 3.pptx
anithaviyyapu237
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Arrays
ArraysArrays
Arrays
Chukka Nikhil Chakravarthy
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
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
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
Dhiviya Rose
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptxMODUL new hlgjg thaybkhvnghgpv7E_02.pptx
MODUL new hlgjg thaybkhvnghgpv7E_02.pptx
lomic31750
 
c unit programming arrays in detail 3.pptx
c unit programming arrays in detail 3.pptxc unit programming arrays in detail 3.pptx
c unit programming arrays in detail 3.pptx
anithaviyyapu237
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
aneebkmct
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
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
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
Dhiviya Rose
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
P M Patil
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 

More from MSridhar18 (13)

Linked List - Part - 2 Linked List - Part - 2
Linked List - Part - 2 Linked List - Part - 2Linked List - Part - 2 Linked List - Part - 2
Linked List - Part - 2 Linked List - Part - 2
MSridhar18
 
Singly Linked List - Singly Linked List - Part -1
Singly Linked List - Singly Linked List - Part -1Singly Linked List - Singly Linked List - Part -1
Singly Linked List - Singly Linked List - Part -1
MSridhar18
 
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
CONCEPT OF ARRAY IN DATA  STRUCTURES CONCEPT OF ARRAY IN DATA  STRUCTURESCONCEPT OF ARRAY IN DATA  STRUCTURES CONCEPT OF ARRAY IN DATA  STRUCTURES
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
MSridhar18
 
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
unit 1 ds.INTRODUCTION TO DATA STRUCTURESunit 1 ds.INTRODUCTION TO DATA STRUCTURES
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
MSridhar18
 
Data Warehouse Introduction to Data Warehouse
Data Warehouse Introduction to Data WarehouseData Warehouse Introduction to Data Warehouse
Data Warehouse Introduction to Data Warehouse
MSridhar18
 
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
Cluster Analysis K-Means Clustering Typically measured by Euclidean distanceCluster Analysis K-Means Clustering Typically measured by Euclidean distance
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
MSridhar18
 
Classification and Cluster 2BCasic Concepts
Classification and  Cluster 2BCasic ConceptsClassification and  Cluster 2BCasic Concepts
Classification and Cluster 2BCasic Concepts
MSridhar18
 
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
MSridhar18
 
Data Structures: A Foundation for Efficient Programming
Data Structures: A Foundation for Efficient ProgrammingData Structures: A Foundation for Efficient Programming
Data Structures: A Foundation for Efficient Programming
MSridhar18
 
DECISION MAKING AND BRANCHING - C Programming
DECISION MAKING AND BRANCHING - C ProgrammingDECISION MAKING AND BRANCHING - C Programming
DECISION MAKING AND BRANCHING - C Programming
MSridhar18
 
Fundamentals of computers - C Programming
Fundamentals of computers - C ProgrammingFundamentals of computers - C Programming
Fundamentals of computers - C Programming
MSridhar18
 
POINTERS AND FILE HANDLING - C Programming
POINTERS AND FILE HANDLING - C ProgrammingPOINTERS AND FILE HANDLING - C Programming
POINTERS AND FILE HANDLING - C Programming
MSridhar18
 
USER DEFINE FUNCTION AND STRUCTURE AND UNION
USER DEFINE FUNCTION AND STRUCTURE AND UNIONUSER DEFINE FUNCTION AND STRUCTURE AND UNION
USER DEFINE FUNCTION AND STRUCTURE AND UNION
MSridhar18
 
Linked List - Part - 2 Linked List - Part - 2
Linked List - Part - 2 Linked List - Part - 2Linked List - Part - 2 Linked List - Part - 2
Linked List - Part - 2 Linked List - Part - 2
MSridhar18
 
Singly Linked List - Singly Linked List - Part -1
Singly Linked List - Singly Linked List - Part -1Singly Linked List - Singly Linked List - Part -1
Singly Linked List - Singly Linked List - Part -1
MSridhar18
 
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
CONCEPT OF ARRAY IN DATA  STRUCTURES CONCEPT OF ARRAY IN DATA  STRUCTURESCONCEPT OF ARRAY IN DATA  STRUCTURES CONCEPT OF ARRAY IN DATA  STRUCTURES
CONCEPT OF ARRAY IN DATA STRUCTURES CONCEPT OF ARRAY IN DATA STRUCTURES
MSridhar18
 
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
unit 1 ds.INTRODUCTION TO DATA STRUCTURESunit 1 ds.INTRODUCTION TO DATA STRUCTURES
unit 1 ds.INTRODUCTION TO DATA STRUCTURES
MSridhar18
 
Data Warehouse Introduction to Data Warehouse
Data Warehouse Introduction to Data WarehouseData Warehouse Introduction to Data Warehouse
Data Warehouse Introduction to Data Warehouse
MSridhar18
 
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
Cluster Analysis K-Means Clustering Typically measured by Euclidean distanceCluster Analysis K-Means Clustering Typically measured by Euclidean distance
Cluster Analysis K-Means Clustering Typically measured by Euclidean distance
MSridhar18
 
Classification and Cluster 2BCasic Concepts
Classification and  Cluster 2BCasic ConceptsClassification and  Cluster 2BCasic Concepts
Classification and Cluster 2BCasic Concepts
MSridhar18
 
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
Linked Lists: A Comprehensive Guide Advantages, various types, and fundamenta...
MSridhar18
 
Data Structures: A Foundation for Efficient Programming
Data Structures: A Foundation for Efficient ProgrammingData Structures: A Foundation for Efficient Programming
Data Structures: A Foundation for Efficient Programming
MSridhar18
 
DECISION MAKING AND BRANCHING - C Programming
DECISION MAKING AND BRANCHING - C ProgrammingDECISION MAKING AND BRANCHING - C Programming
DECISION MAKING AND BRANCHING - C Programming
MSridhar18
 
Fundamentals of computers - C Programming
Fundamentals of computers - C ProgrammingFundamentals of computers - C Programming
Fundamentals of computers - C Programming
MSridhar18
 
POINTERS AND FILE HANDLING - C Programming
POINTERS AND FILE HANDLING - C ProgrammingPOINTERS AND FILE HANDLING - C Programming
POINTERS AND FILE HANDLING - C Programming
MSridhar18
 
USER DEFINE FUNCTION AND STRUCTURE AND UNION
USER DEFINE FUNCTION AND STRUCTURE AND UNIONUSER DEFINE FUNCTION AND STRUCTURE AND UNION
USER DEFINE FUNCTION AND STRUCTURE AND UNION
MSridhar18
 

Recently uploaded (20)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
siemaillard
 
Research Handbook On Environment And Investment Law Kate Miles
Research Handbook On Environment And Investment Law Kate MilesResearch Handbook On Environment And Investment Law Kate Miles
Research Handbook On Environment And Investment Law Kate Miles
mucomousamir
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Rajdeep Bavaliya
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
Sri Guru Arjun Dev Ji .
Sri Guru Arjun Dev Ji                   .Sri Guru Arjun Dev Ji                   .
Sri Guru Arjun Dev Ji .
Balvir Singh
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
Celine George
 
Network Security Essentials 6th Edition.pdf
Network Security Essentials 6th Edition.pdfNetwork Security Essentials 6th Edition.pdf
Network Security Essentials 6th Edition.pdf
datmieu2004
 
How to Configure Subcontracting in Odoo 18 Manufacturing
How to Configure Subcontracting in Odoo 18 ManufacturingHow to Configure Subcontracting in Odoo 18 Manufacturing
How to Configure Subcontracting in Odoo 18 Manufacturing
Celine George
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
siemaillard
 
Research Handbook On Environment And Investment Law Kate Miles
Research Handbook On Environment And Investment Law Kate MilesResearch Handbook On Environment And Investment Law Kate Miles
Research Handbook On Environment And Investment Law Kate Miles
mucomousamir
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Paper 110A | Shadows and Light: Exploring Expressionism in ‘The Cabinet of Dr...
Rajdeep Bavaliya
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18How to Setup Renewal of Subscription in Odoo 18
How to Setup Renewal of Subscription in Odoo 18
Celine George
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo SlidesHow to Manage Orders in Odoo 18 Lunch - Odoo Slides
How to Manage Orders in Odoo 18 Lunch - Odoo Slides
Celine George
 
Sri Guru Arjun Dev Ji .
Sri Guru Arjun Dev Ji                   .Sri Guru Arjun Dev Ji                   .
Sri Guru Arjun Dev Ji .
Balvir Singh
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
Celine George
 
Network Security Essentials 6th Edition.pdf
Network Security Essentials 6th Edition.pdfNetwork Security Essentials 6th Edition.pdf
Network Security Essentials 6th Edition.pdf
datmieu2004
 
How to Configure Subcontracting in Odoo 18 Manufacturing
How to Configure Subcontracting in Odoo 18 ManufacturingHow to Configure Subcontracting in Odoo 18 Manufacturing
How to Configure Subcontracting in Odoo 18 Manufacturing
Celine George
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 

ARRAY's in C Programming Language PPTX.

  • 2. Introduction to Array: What is an Array? An array in C is a collection of similar data types stored in contiguous memory locations. It's a fundamental data structure used to store multiple values under a single name. Declaring an Array To declare an array, you specify the data type, array name, and size: Syntax: data_type array_name[size]; Example: int numbers[5];
  • 3. One Dimentional Array: A one-dimensional array is a linear collection of elements of the same data type, stored in contiguous memory locations. It's like a row of containers, each holding a value of the same type. Declaring a One-Dimensional Array Syntax: data_type array_name[size]; • data_type: The data type of the elements (e.g., int, float, char). • array_name: The name of the array. • size: The number of elements in the array.
  • 4. Accessing Array Elements: To access an element, use its index within square brackets: Syntax: array_name[index] • index: The position of the element (starts from 0). Example: numbers[2] = 30; Initializing an Array: You can initialize an array while declaring it: Syntax: data_type array_name[size] = {value1, value2, ..., valueN}; Example: int marks[5] = {85, 92, 78, 95, 88};
  • 5. Example Program for one dimentional array: #include <stdio.h> int main() { int numbers[5] = {2, 4, 6, 8, 10}; int i; // Accessing and printing array elements for (i = 0; i < 5; i++) { printf("%d ", numbers[i]); } return 0; }
  • 6. Two Dimentional Array: Declaring a Two-Dimensional Array syntax: data_type array_name[rows][columns]; Example: int matrix[3][4]; A two-dimensional array is essentially an array of arrays. It can be visualized as a matrix with rows and columns. Each element in the array is identified by two indices: one for the row and one for the column.
  • 7. Accessing Array Elements: To access an element, use two indices: Syntax: array_name[row][column]; Example: matrix[1][2] = 10; Initializing a Two-Dimensional Array You can initialize a two-dimensional array while declaring it: Syntax: data_type array_name[rows][columns] = {{value11, value12, ...}, {value21, value22, ...}, ...}; Example: int numbers[2][3] = {{1, 2, 3}, {4, 5, 6}};
  • 8. Example Program #include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int i, j; // Accessing and printing array elements for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { printf("%d ", matrix[i][j]); } printf("n"); } return 0; }
  • 9. Multidimensional Array: A multidimensional array is an extension of the concept of a one-dimensional array. It's essentially an array of arrays, allowing you to store data in a tabular or grid-like structure. Declaring a Multidimensional Array: Syntax: data_type array_name[size1][size2][...][sizeN]; Example: int matrix[3][4]; Accessing Array Elements To access an element, use multiple indices separated by commas: Syntax: array_name[index1][index2][...][indexN] Example: matrix[1][2] = 10;
  • 10. Initializing a Multidimensional Array You can initialize a multidimensional array while declaring it: Syntax: data_type array_name[size1][size2] = {{value11, value12, ...}, {value21, value22, ...}, Example: int numbers[2][3] = {{1, 2, 3}, {4, 5, 6}}; ...};
  • 11. Example Program (3D Array) #include <stdio.h> int main() { int cube[2][3][2] = {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}}; int i, j, k; // Accessing and printing array elements for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { for (k = 0; k < 2; k++) { printf("%d ", cube[i][j][k]); } printf("n"); } printf("n"); } return 0; }
  • 12. Character Array and String: Character Arrays A character array in C is simply an array of characters. It's a fundamental building block for handling text data. Declaration: char char_array[size]; • size: The maximum number of characters the array can hold. Example: char message[10] = "Hello";
  • 13. String: Strings In C, a string is essentially a character array with a null character ('0') at the end to mark its termination. This allows functions to determine the length of the string without explicitly storing it. Key points: • Strings are implicitly null-terminated. • You can use string manipulation functions from the string.h library. Example: char greeting[] = "Welcome";
  • 14. Initializing String Variables in C In C, strings are essentially character arrays with a null terminator (0) at the end. There are primarily two methods to initialize a string variable: 1. Direct Initialization Example: char str[] = "Hello, world!" 2. Explicit Initialization Example: char str[14] = {'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '0'};
  • 15. Example: #include <stdio.h> int main() { char str1[] = "Hello"; char str2[6] = {'W', 'o', 'r', 'l', 'd', '0'}; printf("%s %sn", str1, str2); return 0; }
  • 16. Reading Strings from the Terminal: Using scanf() The scanf() function can be used to read a string from the standard input (terminal). However, it has limitations: it stops reading at the first whitespace character (space, tab, newline). Example: #include <stdio.h> int main() { char str[100]; printf("Enter a string: "); scanf("%s", str); printf("You entered: %sn", str); return 0; }
  • 17. Using fgets() The fgets() function is a safer and more flexible way to read a string, including whitespace characters. It reads a specified number of characters or until a newline character is encountered. Example: #include <stdio.h> int main() { char str[100]; printf("Enter a string: "); fgets(str, 100, stdin); printf("You entered: %s", str); return 0; }
  • 18. Writing String to Screen: Using printf() The most common way to write a string to the screen in C is using the printf() function. Example: #include <stdio.h>int main() { char str[] = "Hello, world!"; printf("%sn", str); return 0; } Using puts() Another option is the puts() function, which is specifically designed for writing strings to the standard output. Example: #include <stdio.h>int main() { char str[] = "Hello, world!"; puts(str); return 0; }
  • 19. Comparing Strings in C Using the strcmp() Function The most common and efficient way to compare strings in C is by using the strcmp() function from the string.h library. Syntax: int strcmp(const char *str1, const char *str2); Manual String Comparison While strcmp() is generally preferred, you can also compare strings manually by iterating through characters and comparing them individually. This approach can be useful for specific scenarios or learning purposes.
  • 20. Example Program: #include <stdio.h> int compare_strings(const char *str1, const char *str2) { while (*str1 != '0' && *str2 != '0') { if (*str1 != *str2) { return *str1 - *str2; // Return difference in ASCII values } str1++; str2++; } return *str1 - *str2; // Compare lengths if strings are equal up to this point }
  • 21. int main() { char str1[] = "hello"; char str2[] = "world"; int result = compare_strings(str1, str2); if (result == 0) { printf("Strings are equaln"); } else { printf("Strings are not equaln"); } return 0; }
  • 22. String Handling Functions in C C provides a rich set of functions for manipulating strings. These functions are primarily defined in the string.h header file. Common String Handling Functions Here are some of the most commonly used string handling functions in C: Length of a String • strlen(str): Returns the length of a string (excluding the null terminator). Copying Strings • strcpy(dest, src): Copies the string src to the destination string dest. Be cautious about buffer overflows. • strncpy(dest, src, n): Copies at most n characters from src to dest. Concatenating Strings • strcat(dest, src): Appends src to the end of dest. Be careful about buffer overflows. • strncat(dest, src, n): Appends at most n characters from src to dest.
  • 23. Comparing Strings • strcmp(str1, str2): Compares two strings lexicographically. Returns 0 if equal, a negative value if str1 is less than str2, and a positive value if str1 is greater than str2. • strncmp(str1, str2, n): Compares at most n characters of str1 and str2. Searching in Strings • strchr(str, ch): Finds the first occurrence of character ch in string str. • strrchr(str, ch): Finds the last occurrence of character ch in string str. • strstr(str1, str2): Finds the first occurrence of string str2 in string str1. Converting Case • tolower(ch): Converts a character to lowercase. • toupper(ch): Converts a character to uppercase. Other Useful Functions • strtok(str, delimiters): Breaks a string into tokens based on delimiters. • memset(str, ch, n): Fills a block of memory with a specific character. • memcpy(dest, src, n): Copies a block of memory from src to dest.
  • 24. Example Program #include <stdio.h>#include <string.h>int main() { char str1[] = "hello"; char str2[20]; strcpy(str2, str1); strcat(str2, " world"); printf("%sn", str2); if (strcmp(str1, "hello") == 0) { printf("Strings are equaln"); } char *ptr = strchr(str2, 'o'); if (ptr) { printf("First occurrence of 'o': %sn", ptr); } return 0; }