SlideShare a Scribd company logo
ARRAY in C
• Array is a collection or group of similar data type
  elements stored in contiguous memory.

• The individual data items can be characters, integers,
  floating points numbers and so on .

• Here contiguous memory allocation means array
  occupies contiguous bytes as needed in the memory.
Declaring single dimension Arrays
• We can declare an array by specify its data
  type, name and the number of elements the
  array holds between square brackets
  immediately following the array name.

• Here is the syntax:
     data_type array_name[size];
Declaring single dimension Array
• For example, to declare an integer array which
  contains 10 elements we can do as follows:

     int values[10];
Accessing Single Dimension Array
• We can access array elements via
  indexes array_name[index]. Indexes of array
  starts from 0
• With each subscript enclosed in square
  brackets.

• For example,
     values[0]=5;
     values[1]=10;
     printf(“%d”,values[1]);
Initializing Arrays
• It is like a variable, an array can be initialized.

• To initialize an array, you provide initializing
  values which are enclosed within curly braces
  in the declaration and placed following an
  equals sign after the array name.

• Here is an example of initializing an integer
  array.
          int list[5] = {2,1,3,7,8};
Multi dimensional Arrays:
• Often there is a need to store and manipulate
  two dimensional data structure such as matrices
  & tables.

• Here the array has two subscripts. One subscript
  denotes the row & the other the column.

• The declaration of two dimension arrays is as
  follows:
  data_type array_name[row_size][column_size];
  int m[10][20];
Declaring Multi Dimensional Array
float table [50][50];
char page[50][50];



int num[3][3];
      0    1   2
    0
    1
    2
Accessing two dimensional arrays
int values[2][2];
values[0][0]=1;     values[0][1]=2;
values[1][0]=3;     values[1][1]=4;

int num[2][2]={1,2,3,4};
int matrix[3][3]
={{11,12,13}, {21,22,23}, {32,31,33}};
ARRAY AND STRINGS
• The gets and puts functions:

• The gets and puts functions facilitate the transfer
  of strings between the computer and the
  standard input/output devices.

• Each of these functions accepts a single
  argument. The argument must be a data item
  that represents a string(e.g. character array).
Example of using gets and puts
#include<stdio.h>
void main()
{
    char inne[80];
    gets(line);
    puts(line);
}
The gets and puts functions offer simple
alternatives to the use of scanf and printf for
reading and displaying strings
String library functions
• strlen()
• This function counts a number of characters
  present in a string while giving a call to the
  function.
            char msg[] = “Lord krishna”;
            int n;
            n=strlen(msg);
            printf(“length of string =%d”, n);
String library functions
• strcpy()
• This function copies the contents of one string
  to another.
• The base address of source and target strings
  are supplied to the function.

     char source[] = “Lord Krishna”;
     char target[15];
     strcpy(target, source);
     printf(“Source string is : %s”, source);
     printf(“target string is :%s”,target);
String library functions
• strcat()
• This function concatenates the source string
  at the end of target sting.
           char s[] = “Lord”;
           char t[] = “Krishna”;
           strcat(t,s);
           printf(“source string is %sn”, s);
           printf(“target stirng is %sn”, t);
String library functions
• strcmp()
• This function compares two strings and
  returns some integer value.
• If both the strings are equal then it returns 0
  otherwise it returns some other integer value.
  void main()
  {
      char s1[]=”Jerry”; char s2[]=”Ferry”;
      int j= strcmp(s1, s2);
      printf(“%d”, j);
Understanding Functions
• What is Function?
• A function in C language is a block of code that
  performs a specific task.

• It is reusable i.e. it can be executed from as
  many different parts in a C Program as
  required.

• It also optionally returns a value to the calling
  program
Structure of a Function
<return type> FunctionName (Argument1,
Argument2, Argument3……)
{
    Statement1;
    Statement2;
}
int sum (int x, int y)
{
    int result;
    result = x + y;
    return (result);
}
Types of functions:
 A function may belong to any one of the
 following categories:

• Functions with no arguments and no return
  values.
• Functions with arguments and no return values.
• Functions with arguments and return values.
• Functions that return multiple values.
• Functions with no arguments and return values.
Advantages of using functions:
• It makes possible      top   down     modular
  programming.

• The length of the source program can be
  reduced.

• It becomes uncomplicated to locate and
  separate a faulty function for further study.

• c programmer can use function written by
  others, instead of starting over from scratch.
Function Example
#include <stdio.h>
void printMessage ()
{
   printf ("Programming is fun.n");
}
void main ()
{
   printMessage ();
}
Function Which Return Values
#include <stdio.h>
int add (int x,int y)
{
    int result; result=x+y;
    return(result);
}
void main ()
{
    int total;
    total=add(10,12);
Recursive Function
• Recursive function is a function which
  contains a call to itself.

• Recursive function allows you to divide your
  complex problem into identical single simple
  cases which can handle easily.

• This is also a well-known computer
  programming technique: divide and conquer.
Example of recursive function
# include<stdio.h>
int factorial(int number)
{
     if(number <= 1)
            return 1;
    return number * factorial(number - 1);
}
void main()
{
   int x = 5;
   printf("factorial of %d is %d",x,factorial(x));
}
Scope Rule of Functions
void main( )
{
    int i = 20 ;
    display ( i ) ;
}
void display ( int j )
{
    int k = 35 ;
    printf ( "n%d", j ) ;
    printf ( "n%d", k ) ;
}

More Related Content

What's hot

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
 
Array and string
Array and stringArray and string
Array and string
prashant chelani
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
Maulen Bale
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Janpreet Singh
 
Array ppt
Array pptArray ppt
Array ppt
Kaushal Mehta
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
tanmaymodi4
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
Arrays
ArraysArrays
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
janani thirupathi
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
Shubham Sharma
 
Arrays
ArraysArrays
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 

What's hot (20)

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
 
Array and string
Array and stringArray and string
Array and string
 
Array in c
Array in cArray in c
Array in c
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Array ppt
Array pptArray ppt
Array ppt
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Arrays
ArraysArrays
Arrays
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Arrays
ArraysArrays
Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Chap09
Chap09Chap09
Chap09
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 

Similar to Session 4

Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
GOKULKANNANMMECLECTC
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
Hemantha Kulathilake
 
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
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
SURBHI SAROHA
 
Arrays
ArraysArrays
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptx
KorbanMaheshwari
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
KorbanMaheshwari
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
C
CC
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
Array
ArrayArray
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
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
 
Array
ArrayArray
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
rajatryadav22
 
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
 

Similar to Session 4 (20)

Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
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
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptx
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
C
CC
C
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
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
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Array
ArrayArray
Array
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
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
 
Array
ArrayArray
Array
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
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
 

Recently uploaded

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Session 4

  • 1. ARRAY in C • Array is a collection or group of similar data type elements stored in contiguous memory. • The individual data items can be characters, integers, floating points numbers and so on . • Here contiguous memory allocation means array occupies contiguous bytes as needed in the memory.
  • 2. Declaring single dimension Arrays • We can declare an array by specify its data type, name and the number of elements the array holds between square brackets immediately following the array name. • Here is the syntax: data_type array_name[size];
  • 3. Declaring single dimension Array • For example, to declare an integer array which contains 10 elements we can do as follows: int values[10];
  • 4. Accessing Single Dimension Array • We can access array elements via indexes array_name[index]. Indexes of array starts from 0 • With each subscript enclosed in square brackets. • For example, values[0]=5; values[1]=10; printf(“%d”,values[1]);
  • 5. Initializing Arrays • It is like a variable, an array can be initialized. • To initialize an array, you provide initializing values which are enclosed within curly braces in the declaration and placed following an equals sign after the array name. • Here is an example of initializing an integer array. int list[5] = {2,1,3,7,8};
  • 6. Multi dimensional Arrays: • Often there is a need to store and manipulate two dimensional data structure such as matrices & tables. • Here the array has two subscripts. One subscript denotes the row & the other the column. • The declaration of two dimension arrays is as follows: data_type array_name[row_size][column_size]; int m[10][20];
  • 7. Declaring Multi Dimensional Array float table [50][50]; char page[50][50]; int num[3][3]; 0 1 2 0 1 2
  • 8. Accessing two dimensional arrays int values[2][2]; values[0][0]=1; values[0][1]=2; values[1][0]=3; values[1][1]=4; int num[2][2]={1,2,3,4}; int matrix[3][3] ={{11,12,13}, {21,22,23}, {32,31,33}};
  • 9. ARRAY AND STRINGS • The gets and puts functions: • The gets and puts functions facilitate the transfer of strings between the computer and the standard input/output devices. • Each of these functions accepts a single argument. The argument must be a data item that represents a string(e.g. character array).
  • 10. Example of using gets and puts #include<stdio.h> void main() { char inne[80]; gets(line); puts(line); } The gets and puts functions offer simple alternatives to the use of scanf and printf for reading and displaying strings
  • 11. String library functions • strlen() • This function counts a number of characters present in a string while giving a call to the function. char msg[] = “Lord krishna”; int n; n=strlen(msg); printf(“length of string =%d”, n);
  • 12. String library functions • strcpy() • This function copies the contents of one string to another. • The base address of source and target strings are supplied to the function. char source[] = “Lord Krishna”; char target[15]; strcpy(target, source); printf(“Source string is : %s”, source); printf(“target string is :%s”,target);
  • 13. String library functions • strcat() • This function concatenates the source string at the end of target sting. char s[] = “Lord”; char t[] = “Krishna”; strcat(t,s); printf(“source string is %sn”, s); printf(“target stirng is %sn”, t);
  • 14. String library functions • strcmp() • This function compares two strings and returns some integer value. • If both the strings are equal then it returns 0 otherwise it returns some other integer value. void main() { char s1[]=”Jerry”; char s2[]=”Ferry”; int j= strcmp(s1, s2); printf(“%d”, j);
  • 15. Understanding Functions • What is Function? • A function in C language is a block of code that performs a specific task. • It is reusable i.e. it can be executed from as many different parts in a C Program as required. • It also optionally returns a value to the calling program
  • 16. Structure of a Function <return type> FunctionName (Argument1, Argument2, Argument3……) { Statement1; Statement2; } int sum (int x, int y) { int result; result = x + y; return (result); }
  • 17. Types of functions: A function may belong to any one of the following categories: • Functions with no arguments and no return values. • Functions with arguments and no return values. • Functions with arguments and return values. • Functions that return multiple values. • Functions with no arguments and return values.
  • 18. Advantages of using functions: • It makes possible top down modular programming. • The length of the source program can be reduced. • It becomes uncomplicated to locate and separate a faulty function for further study. • c programmer can use function written by others, instead of starting over from scratch.
  • 19. Function Example #include <stdio.h> void printMessage () { printf ("Programming is fun.n"); } void main () { printMessage (); }
  • 20.
  • 21. Function Which Return Values #include <stdio.h> int add (int x,int y) { int result; result=x+y; return(result); } void main () { int total; total=add(10,12);
  • 22. Recursive Function • Recursive function is a function which contains a call to itself. • Recursive function allows you to divide your complex problem into identical single simple cases which can handle easily. • This is also a well-known computer programming technique: divide and conquer.
  • 23. Example of recursive function # include<stdio.h> int factorial(int number) { if(number <= 1) return 1; return number * factorial(number - 1); } void main() { int x = 5; printf("factorial of %d is %d",x,factorial(x)); }
  • 24. Scope Rule of Functions void main( ) { int i = 20 ; display ( i ) ; } void display ( int j ) { int k = 35 ; printf ( "n%d", j ) ; printf ( "n%d", k ) ; }