SlideShare a Scribd company logo
Recall
• Difference between while and do while?
• Difference between == and =
• Difference between break and continue?
• What is the difference between i++ and
++i
• What if i didn’t give break in switch?
• What is the difference between logical
operators and relational operators
Introduction to C
functions - Arrays – structures - pointers
Week 2- day 2
Functions
Functions
• A function is a group of statements that
together perform a task.
return_type function_name ( parameter list )
{
body of the function
}
Eg: main()
{
Printf(“hello world”);
Functions
int equation(int num1, int num2)
{
int result;
result = num1*num1+2*num1*num2+num2*num2;
return result;
}
Return Type
Function name
Arguments
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ;
Printf(“%d”,c);
}
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
//Function body / function Definition
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
Should I use the same variable names?
Are they same of what I used in main() ?
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
Absolutely not !!!
Variable a in equation() is different from
varaible a in main(). There is no
connection between those two
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
What is this return???
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
Return will simply send value out of
function to whomsoever it was called
#include<stdio.h>
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
Can i write the whole function body after
main function??
#include<stdio.h>
int equation(int a, int b) ;
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
Yes you can. But only additional thing you
need to do is
#include<stdio.h>
int equation(int a, int b) ;
Int main ()
{
int a,b,c;
Printf(“Enter the number”);
Scanf(“%d %d”,&a ,&b);
c = equation (a,b) ; // Calling the function
Printf(“%d”,c);
}
int equation(int a, int b)
{
int c;
c= a*a+2*a*b+b*b;
return c;
}
You must declare it at the beginning
Arrays
Arrays
• Is a collection of data of same type with
common name
• Eg: int a[6]
A[5]
A[4]
A[3]
A[2]
A[1]
A[0]
Memory
Each Cell will be size of int
Example
Main()
{
int a[10];
For(i=0;i<10;i++)
Scanf(“%d”,&a[i]);
For(i=0;i<10;i++)
printf(“%d”, a[i]);
}`
Strings in C
• There is no string data type in C
• But we can do the same with character
array in C
– Eg: char a[8] =“baabtra”//enables us to store
string with 6 characters
/0
A
R
T
B
A
A
B
A[7]
A[6]
a[5]
a[4]
a[3]
a[2]
a[1]
a[0]
main()
{
Char a[7]=“baabtra”; //Correct
Char *p=“baabtra”; //Correct
a=“baabtra”; //Incorrect
Scanf(“%s”,&a); //Correct
Scanf(“%s”, a); //Correct;But
why?? will discuss soon
Printf(“%s”,a);
}
Structures
• A structure is a collection of variables
under a single name
• These variables can be of different types,
and each has a name which is used to
select it from the structure.
struct struct_name
{
//Variable declarations;
}
Why structures?
• A structure is a convenient way of
grouping several pieces of related
information together.
• Eg: suppose there are several variables
called name,age,gender related to a
student . So we can bring all of them
under one name student using structures
• Eg: struct student
{
Char name[25];
Int age;
struct student
{
Char gender;
Int age;
}
main()
{
Struct student john,Mary;
John.age=15;
John.gender=“m”;
Mary.age=16;
Mary.gender=“f”;
}
age
gender
Student
Pointers
• Pointers simply points to locations in
memory
• Each variables will be having a address in
the memory. So pointer is just another
variable which simply stores the address
of it
Main()
{
int a,b, *p,*q;
1002
1001
25
99
1004
1003
1002
1001
q
p
b
a
Main()
{
int a,*p;
a=15;
P=&a;
Printf(“%d,%d ”,&a,p); // Will print 1001,1001
Printf (“%d, %d”,a,*p); // Will print 15,15
}
1001
15
1002
1001
p
a
Character array as pointer
Character array is a pointer to the first location of
a group of locations
Eg : char a[10];
Here a stores memory address of a[0]
main()
{
char a[10]="baabtra";
printf("%d %d",&a[0],a); // will print the
same address
A
R
T
B
A
A
B
A[6]
a[5]
a[4]
a[3]
a[2]
a[1]
a[0]
1006
1005
1004
1003
1002
1001
1000
Questions?
“A good question deserve a good
grade…”
Self Check !!
Self - Check
#include<stdio.h>
Main()
{
Int a,b,c;
Printf(“Sum = %d”,sum(a,b));
}
Sum(int a,int b)
{
Return a+b;
}
Self - Check
#include<stdio.h>
Int sum(int a,int b)
Main()
{
Int a,b,c;
Printf(“Sum = %d”,sum(a,b));
}
Int sum(int a,int b)
{
Return a+b;
}
Self- Check
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A.2, 1,
15
B.1, 2, 5
C.3, 2,
15
D.2, 3,
Self- Check
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
A.2, 1, 1
5
B.1, 2, 5
C.3, 2, 1
5
D.2, 3, 2
Self- Check
• A pointer to a block of memory is
effectively same as an array
A.True
B.False
Self- Check
• A pointer to a block of memory is
effectively same as an array
A.True
B.False
Self- Check
Which of the following are themselves
a collection of different data types?
a) string
b) structures
c) char
d) All of the mentioned
Self- Check
Which of the following are themselves
a collection of different data types?
a) string
b) structures
c) char
d) All of the mentioned
Self- Check
Which of the following cannot
be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
Self- Check
Which of the following cannot
be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
Self- Check
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s;
printf("%ct%c", p[0], s[1]);
}
a) Run time err
b) h h
c) h e
d) h l
Self- Check
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s;
printf("%ct%c", p[0], s[1]);
}
a) Run time err
b) h h
c) h e
d) h l
Self- Check
#include<stdio.h>
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"} };
printf("%d ", c[1].courseno);
printf("%sn", (*(c+2)).coursename);
return 0;
}
A.103 DotNet
B.102 Java
C.103 PHP
D.104 DotNet
Self- Check
#include<stdio.h>
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"} };
printf("%d ", c[1].courseno);
printf("%sn", (*(c+2)).coursename);
return 0;
}
A.104 DotNet
B.102 Java
C.103 PHP
D.103 DotNet
Self- Check
#include <stdio.h>
void foo( int[] );
int main()
{
int ary[4] = {1, 2, 3, 4};
foo(ary);
printf("%d ", ary[0]);
}
void foo(int p[4])
{
int i = 10;
p = &i;
printf("%d ", p[0]);
}
a) 10 10
b) Compile time
c) 10 1
d) Undefined be
Self- Check
#include <stdio.h>
void foo( int[] );
int main()
{
int ary[4] = {1, 2, 3, 4};
foo(ary);
printf("%d ", ary[0]);
}
void foo(int p[4])
{
Int i=10;
p = &i;
printf("%d ", p[0]);
}
a) 10 10
b) Compile time
c) 10 1
d) Undefined be
End of Day 2
Ad

More Related Content

What's hot (20)

Data struture lab
Data struture labData struture lab
Data struture lab
krishnamurthy Murthy.Tt
 
L7 pointers
L7 pointersL7 pointers
L7 pointers
Kathmandu University
 
6. function
6. function6. function
6. function
웅식 전
 
Arrays
ArraysArrays
Arrays
fahadshakeel
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
argusacademy
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
SANTOSH RATH
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
Saket Pathak
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Make Mannan
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
mohamed sikander
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
Syed Mustafa
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
Radha Maruthiyan
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
Divya Kumari
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
argusacademy
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
SANTOSH RATH
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
Saket Pathak
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Make Mannan
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
mohamed sikander
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
Syed Mustafa
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
Radha Maruthiyan
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
Divya Kumari
 

Similar to Introduction to c part 2 (20)

Lecture_3 the functions parameters andrecursion .pptx
Lecture_3 the functions parameters andrecursion .pptxLecture_3 the functions parameters andrecursion .pptx
Lecture_3 the functions parameters andrecursion .pptx
Dr. Amna Mohamed
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Principals of Programming in CModule -5.pdf
Principals of Programming in CModule -5.pdfPrincipals of Programming in CModule -5.pdf
Principals of Programming in CModule -5.pdf
anilcsbs
 
Chp 3 C++ for newbies, learn fast and earn fast
Chp 3 C++ for newbies, learn fast and earn fastChp 3 C++ for newbies, learn fast and earn fast
Chp 3 C++ for newbies, learn fast and earn fast
nhbinaaa112
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
Pradipta Mishra
 
C language
C languageC language
C language
Priya698357
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
Emertxe Information Technologies Pvt Ltd
 
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfLDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
Vedant Gavhane
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
Animesh Chaturvedi
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu
 
Principals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdfPrincipals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
Animesh Chaturvedi
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
HarithaRanasinghe
 
Functions
FunctionsFunctions
Functions
SANTOSH RATH
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
mohd_mizan
 
Lecture_3 the functions parameters andrecursion .pptx
Lecture_3 the functions parameters andrecursion .pptxLecture_3 the functions parameters andrecursion .pptx
Lecture_3 the functions parameters andrecursion .pptx
Dr. Amna Mohamed
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Principals of Programming in CModule -5.pdf
Principals of Programming in CModule -5.pdfPrincipals of Programming in CModule -5.pdf
Principals of Programming in CModule -5.pdf
anilcsbs
 
Chp 3 C++ for newbies, learn fast and earn fast
Chp 3 C++ for newbies, learn fast and earn fastChp 3 C++ for newbies, learn fast and earn fast
Chp 3 C++ for newbies, learn fast and earn fast
nhbinaaa112
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
Pradipta Mishra
 
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfLDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
Vedant Gavhane
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
Yi-Hsiu Hsu
 
Principals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdfPrincipals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
Animesh Chaturvedi
 
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
baabtra.com - No. 1 supplier of quality freshers
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
baabtra.com - No. 1 supplier of quality freshers
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
baabtra.com - No. 1 supplier of quality freshers
 
Blue brain
Blue brainBlue brain
Blue brain
baabtra.com - No. 1 supplier of quality freshers
 
5g
5g5g
5g
baabtra.com - No. 1 supplier of quality freshers
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Ad

Recently uploaded (20)

AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Bepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firmBepents tech services - a premier cybersecurity consulting firm
Bepents tech services - a premier cybersecurity consulting firm
Benard76
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 

Introduction to c part 2

  • 1. Recall • Difference between while and do while? • Difference between == and = • Difference between break and continue? • What is the difference between i++ and ++i • What if i didn’t give break in switch? • What is the difference between logical operators and relational operators
  • 2. Introduction to C functions - Arrays – structures - pointers Week 2- day 2
  • 4. Functions • A function is a group of statements that together perform a task. return_type function_name ( parameter list ) { body of the function } Eg: main() { Printf(“hello world”);
  • 5. Functions int equation(int num1, int num2) { int result; result = num1*num1+2*num1*num2+num2*num2; return result; } Return Type Function name Arguments
  • 6. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; Printf(“%d”,c); }
  • 7. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } //Function body / function Definition
  • 8. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } Should I use the same variable names? Are they same of what I used in main() ?
  • 9. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } Absolutely not !!! Variable a in equation() is different from varaible a in main(). There is no connection between those two
  • 10. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } What is this return???
  • 11. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } Return will simply send value out of function to whomsoever it was called
  • 12. #include<stdio.h> int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } Can i write the whole function body after main function??
  • 13. #include<stdio.h> int equation(int a, int b) ; Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } Yes you can. But only additional thing you need to do is
  • 14. #include<stdio.h> int equation(int a, int b) ; Int main () { int a,b,c; Printf(“Enter the number”); Scanf(“%d %d”,&a ,&b); c = equation (a,b) ; // Calling the function Printf(“%d”,c); } int equation(int a, int b) { int c; c= a*a+2*a*b+b*b; return c; } You must declare it at the beginning
  • 16. Arrays • Is a collection of data of same type with common name • Eg: int a[6] A[5] A[4] A[3] A[2] A[1] A[0] Memory Each Cell will be size of int
  • 18. Strings in C • There is no string data type in C • But we can do the same with character array in C – Eg: char a[8] =“baabtra”//enables us to store string with 6 characters /0 A R T B A A B A[7] A[6] a[5] a[4] a[3] a[2] a[1] a[0]
  • 19. main() { Char a[7]=“baabtra”; //Correct Char *p=“baabtra”; //Correct a=“baabtra”; //Incorrect Scanf(“%s”,&a); //Correct Scanf(“%s”, a); //Correct;But why?? will discuss soon Printf(“%s”,a); }
  • 20. Structures • A structure is a collection of variables under a single name • These variables can be of different types, and each has a name which is used to select it from the structure. struct struct_name { //Variable declarations; }
  • 21. Why structures? • A structure is a convenient way of grouping several pieces of related information together. • Eg: suppose there are several variables called name,age,gender related to a student . So we can bring all of them under one name student using structures • Eg: struct student { Char name[25]; Int age;
  • 22. struct student { Char gender; Int age; } main() { Struct student john,Mary; John.age=15; John.gender=“m”; Mary.age=16; Mary.gender=“f”; } age gender Student
  • 23. Pointers • Pointers simply points to locations in memory • Each variables will be having a address in the memory. So pointer is just another variable which simply stores the address of it Main() { int a,b, *p,*q; 1002 1001 25 99 1004 1003 1002 1001 q p b a
  • 24. Main() { int a,*p; a=15; P=&a; Printf(“%d,%d ”,&a,p); // Will print 1001,1001 Printf (“%d, %d”,a,*p); // Will print 15,15 } 1001 15 1002 1001 p a
  • 25. Character array as pointer Character array is a pointer to the first location of a group of locations Eg : char a[10]; Here a stores memory address of a[0] main() { char a[10]="baabtra"; printf("%d %d",&a[0],a); // will print the same address A R T B A A B A[6] a[5] a[4] a[3] a[2] a[1] a[0] 1006 1005 1004 1003 1002 1001 1000
  • 26. Questions? “A good question deserve a good grade…”
  • 28. Self - Check #include<stdio.h> Main() { Int a,b,c; Printf(“Sum = %d”,sum(a,b)); } Sum(int a,int b) { Return a+b; }
  • 29. Self - Check #include<stdio.h> Int sum(int a,int b) Main() { Int a,b,c; Printf(“Sum = %d”,sum(a,b)); } Int sum(int a,int b) { Return a+b; }
  • 30. Self- Check int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; } A.2, 1, 15 B.1, 2, 5 C.3, 2, 15 D.2, 3,
  • 31. Self- Check int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; } A.2, 1, 1 5 B.1, 2, 5 C.3, 2, 1 5 D.2, 3, 2
  • 32. Self- Check • A pointer to a block of memory is effectively same as an array A.True B.False
  • 33. Self- Check • A pointer to a block of memory is effectively same as an array A.True B.False
  • 34. Self- Check Which of the following are themselves a collection of different data types? a) string b) structures c) char d) All of the mentioned
  • 35. Self- Check Which of the following are themselves a collection of different data types? a) string b) structures c) char d) All of the mentioned
  • 36. Self- Check Which of the following cannot be a structure member? a) Another structure b) Function c) Array d) None of the mentioned
  • 37. Self- Check Which of the following cannot be a structure member? a) Another structure b) Function c) Array d) None of the mentioned
  • 38. Self- Check #include <stdio.h> void main() { char *s= "hello"; char *p = s; printf("%ct%c", p[0], s[1]); } a) Run time err b) h h c) h e d) h l
  • 39. Self- Check #include <stdio.h> void main() { char *s= "hello"; char *p = s; printf("%ct%c", p[0], s[1]); } a) Run time err b) h h c) h e d) h l
  • 40. Self- Check #include<stdio.h> struct course { int courseno; char coursename[25]; }; int main() { struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} }; printf("%d ", c[1].courseno); printf("%sn", (*(c+2)).coursename); return 0; } A.103 DotNet B.102 Java C.103 PHP D.104 DotNet
  • 41. Self- Check #include<stdio.h> struct course { int courseno; char coursename[25]; }; int main() { struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} }; printf("%d ", c[1].courseno); printf("%sn", (*(c+2)).coursename); return 0; } A.104 DotNet B.102 Java C.103 PHP D.103 DotNet
  • 42. Self- Check #include <stdio.h> void foo( int[] ); int main() { int ary[4] = {1, 2, 3, 4}; foo(ary); printf("%d ", ary[0]); } void foo(int p[4]) { int i = 10; p = &i; printf("%d ", p[0]); } a) 10 10 b) Compile time c) 10 1 d) Undefined be
  • 43. Self- Check #include <stdio.h> void foo( int[] ); int main() { int ary[4] = {1, 2, 3, 4}; foo(ary); printf("%d ", ary[0]); } void foo(int p[4]) { Int i=10; p = &i; printf("%d ", p[0]); } a) 10 10 b) Compile time c) 10 1 d) Undefined be
  翻译: