SlideShare a Scribd company logo
1 of 52
Mohammed Sikander
Technical Lead
CranesVarsity (www.cranesvarsity.com)
Mohammed.sikander@cranessoftware.com
int countNodes( Node *root)
{
if(root == NULL)
return 0;
int leftNodes = countNodes(root->left);
int rightNodes = countNodes(root->right);
return leftNodes + rightNodes + 1; //+1 for current node
}
int countLeaf( Node *root)
{
if(root == NULL)
return 0;
if(root->left == NULL && root->right == NULL)
return 1;
int leftLeafNodes = countLeaf(root->left);
int rightLeafNodes = countLeaf(root->right);
return leftLeafNodes + rightLeafNodes;
}
int calculateHeight( Node *root)
{
if(root == NULL)
return 0;
int leftHeight = calculateHeight(root->left);
int rightHeight = calculateHeight (root->right);
return max(leftHeight , rightHeight) + 1;
}
FILE1.C
int x = 5;
void print( )
int main( )
{
print( );
printf(“Main x = %d n”,x);
}
FILE2.C
extern int x;
void print( )
{
printf(“Print : x = %d n”,x);
}
FILE1.C
extern int x;
void print( );
int main( )
{
printf(“Main x = %d n”,x);
print( );
}
FILE2.C
int x = 5;
void print( )
{
printf(“Print : x = %d n”,x);
}
Learning : We require one definition and a declaration in
other file(s). It does not matter which file contains the
definition.
FILE1.C
int x = 8;
void print( );
int main( )
{
printf(“Main x = %d n”,x);
print( );
}
FILE2.C
int x = 5;
void print( )
{
printf(“Print : x = %d n”,x);
}
 Multiple Definition Error.
 An external declaration for an object is a
definition if it has an initializer (Refer K&R
A10.2 ).
 As both have initialization, both are
definition.
 We will get Linker Error (not a compile-time
error)
FILE1.C
static int x;
void print( );
int main( )
{
printf(“Main x = %d n”,x);
print( );
}
FILE2.C
int x = 5;
void print( )
{
printf(“Print : x = %d n”,x);
}
 X in file1 has internal linkage and is not visible
during linking of multiple files.
 No error of multiple definition.
 File1 will access the variable x defined in file1,
as it is not initialized, the default value is 0.
 File2 will access the variable x defined in file2,
whose value is 5
FILE1.C
static int x = 8;
void print( );
int main( )
{
extern int x;
printf(“Main x = %d n”,x);
print( );
}
Output is 8.
Extern says that the variable
is defined externally, within
the same file / other file. As
an external definition is
found, it refers to it.
FILE1.C
int x ;
void print( );
int main( )
{
printf(“Main x = %d n”,x);
print( );
}
FILE2.C
int x = 5;
void print( )
{
printf(“Print : x = %d n”,x);
}
 An external object declaration that does not have an
initializer, and does not contain the extern specifier, is a
tentative definition
 If a definition for an object appears , any tentative definitions
are treated merely as redundant declarations. If no definition
for the object appears, all its tentative definitions become a
single definition with initializer 0.
 The declaration of x in file1 is tentative definition;
 As the definition for x is found in file2, x in file1 is treated as
declaration only.
FILE1.C
int x ;
void print( );
int main( )
{
printf(“Main x = %d n”,x);
print( );
printf(“Main x = %d n”,x);
}
FILE2.C
int x;
void print( )
{
x = 5;
printf(“Print : x = %d n”,x);
}
FILE1.C
int arr[5] = {2,5,7};
void print( );
int main( )
{
print( );
}
FILE2.C
extern int arr[ ];
void print( )
{
printf(“ %d “ , arr[0] );
}
FILE1.C
int arr[5] = {2,5,7};
void print( );
int main( )
{
print( );
}
FILE2.C
extern int *arr;
void print( )
{
printf(“ %d “ , arr[0] );
}
FILE1.C
int arr[5];
void print( );
int main( )
{
print( );
}
FILE2.C
extern int arr[ ];
void print( )
{
printf(“ %d “ , sizeof(arr) );
}
FILE1.C
int arr[5] = {2 , 5 , 8};
void print(int arr[]);
int main( )
{
print( arr );
}
FILE2.C
void print(int arr[] )
{
printf(“ %d “ , sizeof(arr) );
}
FILE1.C
int arr[5] = {2 , 5 , 8};
void print(int arr[]);
int main( )
{
print( arr );
}
FILE2.C
void print(int *arr )
{
printf(“ %d “ , arr[0] );
}
FILE1.C
char arr[25] = “RADHA”;
void print( );
int main( )
{
print( );
}
FILE2.C
extern char *arr;
void print( )
{
printf(“ %s “ , arr);
}
 Draw an Expression Tree for the given
expression and traverse in inorder,preorder
and postorder.
 A + B * C
 A * (B + C)
int *pi;
char *pc;
short int *psi;
printf(“ %d n”,sizeof(pi));
printf(“ %d n”,sizeof(pc));
printf(“ %d n”,sizeof(psi));
int *pi;
char *pc;
short int *psi;
printf(“ %d n”,sizeof(*pi));
printf(“ %d n”,sizeof(*pc));
printf(“ %d n”,sizeof(*psi));
int *pi = (int *)2000;
char *pc = (char *)2000;
pi++;
pc++;
printf(“ %u %u “ , pi , pc);
int x = 0x1234;
char c = x;
printf(“ %x “ , c);
const int x = 10;
1.int * const ptr1 = &x;
2.int const * ptr2 = &x;
3.const int * ptr3 = &x;
void update(int *p)
{
*p = *p + 5;
}
int main( )
{
int x = 10;
int *ptr = &x;
update(ptr);
printf(“x = %d “ , x);
}
void update(int *p)
{
p = p + 1;
}
int main( )
{
int arr[ ] = {10 , 12 , 25 , 45};
int *ptr = arr;
update(ptr);
printf(“*ptr = %d “ , *ptr);
}
void update(int *p)
{
*p = *p + 1;
}
int main( )
{
int arr[ ] = {10 , 12 , 25 , 45};
int *ptr = arr;
update(ptr);
printf(“*ptr = %d “ , *ptr);
}
void update(char *str)
{
str = “Devendra”;
}
int main( )
{
char *name = “Nimisha”;
update(name);
printf(“ %s n” , name);
}
void update(char *str)
{
str[0] = ‘H’;
}
int main( )
{
char name[ ] = “Nimisha”;
char *ptr = name;
update(ptr);
printf(“ %s n” , name);
}
void update(char *str)
{
*++str = ‘a’;
}
int main( )
{
char name[ ] = “Nimisha”;
char *ptr = name;
update(ptr);
printf(“ %s n” , name);
}
int main( )
{
char names[]
[10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”};
printf(“ %__ “ , *(names + 2) + 3);
printf(“ %__ “ , **(names + 2) + 3);
}
int main( )
{
char names[][10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”};
1. printf(“ %s “ , *(++names));
2. printf(“ %s “ , ++*(names));
3. printf(“ %c “ , ++**(names));
}
int main( )
{
char *names[10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”};
1. printf(“ %s “ , *(++names));
2. printf(“ %s “ , ++*(names));
3. printf(“ %c “ , ++**(names));
}
struct Student
{
int id;
char name[20];
};
int main( )
{
struct Student s1 = {1 , “Ayushi”};
struct Student s2 = {2 , “Ayushi”};
if(s1.name == s2.name)
printf(“Equal”);
else
printf(“Not Equal”);
}
char *names[ ] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”};
printf(“ %d “ , sizeof(names));
printf(“ %d “ , sizeof(names[0]));
char names[ ][10] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”};
printf(“ %d “ , sizeof(names));
printf(“ %d “ , sizeof(names[0]));
void display( char *names[ ])
{
printf(“Display : %d n “ , sizeof(names));
}
int main( )
{
char *names[ ] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”};
printf(“Main : %d n“ , sizeof(names));
display( names );
}
static int x = 5;
int main( )
{
int x;
printf(“x = %d n”,x);
}
static int x = 5;
int main( )
{
extern int x;
printf(“x = %d n”,x);
}
int a = 5;
int b;
static int c = 7;
static int d;
int main( )
{
}
• Mention the memory segments of
variables after compiling (.o file) and
after linking (a.out)
• What is the difference between a
and c.
• Use nm utility to view the memory
segments
$gcc –c file.c
$nm file.o
$gcc file.c
$nm ./a.out
void func( );
int x;
int main( )
{
x = 5;
func( );
printf(“x = %d “ , x);
}
int x;
void func( )
{
x = 10;
}
[sikander@localhost ~]$ gcc -c f1.c
[sikander@localhost ~]$ gcc -c f2.c
[sikander@localhost ~]$ nm f1.o
U func
00000000 T main
U printf
00000004 C x
[sikander@localhost ~]$ nm f2.o
00000000 T func
00000004 C x
[sikander@localhost ~]$ gcc f1.o f2.o
[sikander@localhost ~]$ nm a.out
080495ac B x
void func( );
int x = 5;
int main( )
{
func( );
printf(“x = %d “ , x);
}
int x = 10;
void func( )
{
x++;
}
 [sikander@localhost ~]$ gcc -c f1.c
 [sikander@localhost ~]$ gcc -c f2.c
 [sikander@localhost ~]$ nm f1.o
 00000000 D x
 [sikander@localhost ~]$ nm f2.o
 00000000 D x
 [sikander@localhost ~]$ gcc f1.o f2.o
 f2.o(.data+0x0): multiple definition of `x'
 f1.o(.data+0x0): first defined here
 collect2: ld returned 1 exit status
C C
B
C D
D
D D
Multiple Definition
d d
No Conflict, two different variables
b b
No Conflict, two different variables
d b
No Conflict, two different variables
b d
No Conflict, two different variables
b D
No Conflict, two different variables
int x ; //C
int main( )
{
printf(“Main &x= %p” , &x);
printf(“x = %d n”, x);
func( );
}
int x ; //C
void func( )
{
printf(“Func &x= %p” , &x);
printf(“x = %d n”, x);
}
int x ; //C
int main( )
{
printf(“Main &x= %p” , &x);
printf(“x = %d n”, x);
func( );
}
int x = 5 ; //D
void func( )
{
printf(“Func &x= %p” , &x);
printf(“x = %d n”, x);
}
void func( );
int x = 5; //D
int main( )
{
printf(“Main &x= %p” , &x);
printf(“x = %d n”, x);
func( );
}
int x = 10; //D
void func( )
{
printf(“Func &x= %p” , &x);
printf(“x = %d n”, x);
}
void func( );
static int x = 5; //d
int main( )
{
printf(“Main &x= %p” , &x);
printf(“x = %d n”, x);
func( );
}
int x = 10; //D
void func( )
{
printf(“Func &x= %p” , &x);
printf(“x = %d n”, x);
}
const int x = 10; //Read Only
int main( )
{
const int y = 5; //Stack
}
const int x = 10; //Read Only
int main( )
{
const int y = 5; //Stack
printf(“Enter the value for local const variable : “);
scanf(“ %d”,&y);
printf(“Local Const = %d n” , y);
printf(“Enter the value for global const variable : “);
scanf(“ %d”,&x);
printf(“Global Const = %d n”,x);
}
[sikander@localhost ~]$ ./a.out
Enter the value for local const variable : 89
Local Const = 89
Enter the value for global const variable : 6
Segmentation fault
 [sikander@localhost ~]$ nm f1.o
 00000000 t display
 0000000a T main
 00000005 T print
static void display()
{
}
void print()
{
}
int main( )
{
display( );
print( );
}

More Related Content

What's hot

Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functionsmohamed sikander
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphismmohamed sikander
 
Double linked list
Double linked listDouble linked list
Double linked listSayantan Sur
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
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 Overloadingmohamed sikander
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st StudyChris Ohk
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th StudyChris Ohk
 
Circular linked list
Circular linked listCircular linked list
Circular linked listSayantan Sur
 
Single linked list
Single linked listSingle linked list
Single linked listSayantan Sur
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 

What's hot (20)

Container adapters
Container adaptersContainer adapters
Container adapters
 
C programs
C programsC programs
C programs
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
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
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
Double linked list
Double linked listDouble linked list
Double linked list
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 

Viewers also liked

If You Give a Mongolian Some Money
If You Give a Mongolian Some MoneyIf You Give a Mongolian Some Money
If You Give a Mongolian Some Moneymjheg
 
Robert Ng Resume 2016
Robert Ng Resume 2016Robert Ng Resume 2016
Robert Ng Resume 2016Robert Ng
 
Design driven innovation - Turkey Innovation Week 20151204
Design driven innovation - Turkey Innovation Week 20151204Design driven innovation - Turkey Innovation Week 20151204
Design driven innovation - Turkey Innovation Week 20151204CLICKNL
 
Cac – uni papua at banda aceh
Cac – uni papua at banda aceh Cac – uni papua at banda aceh
Cac – uni papua at banda aceh Uni Papua Football
 
Integrative Destination Management - Cooperation
Integrative Destination Management - CooperationIntegrative Destination Management - Cooperation
Integrative Destination Management - CooperationBarbara Pirchner
 
KB 3 - Manajemen Kebidanan Pada Ibu Nifas
KB 3 - Manajemen Kebidanan Pada Ibu NifasKB 3 - Manajemen Kebidanan Pada Ibu Nifas
KB 3 - Manajemen Kebidanan Pada Ibu NifasUwes Chaeruman
 
Improving the business environment and access to finance for SMEs
Improving the business environment and access to finance for SMEsImproving the business environment and access to finance for SMEs
Improving the business environment and access to finance for SMEsOECDglobal
 
[2016 K-global 스마트디바이스톤] inSpot
[2016 K-global 스마트디바이스톤] inSpot[2016 K-global 스마트디바이스톤] inSpot
[2016 K-global 스마트디바이스톤] inSpotJunyoung Jung
 
CSR Activity in Hotel Industry
CSR Activity in Hotel IndustryCSR Activity in Hotel Industry
CSR Activity in Hotel IndustryPriyadarshani Jain
 
10 stages linear arrow showing the process flow direction slide shop powerpoi...
10 stages linear arrow showing the process flow direction slide shop powerpoi...10 stages linear arrow showing the process flow direction slide shop powerpoi...
10 stages linear arrow showing the process flow direction slide shop powerpoi...SlideTeam.net
 
Project functionsc++
Project functionsc++Project functionsc++
Project functionsc++Ismail Adam
 
Future Proofing Your Portfolio
Future Proofing Your PortfolioFuture Proofing Your Portfolio
Future Proofing Your PortfolioJulian Scaff
 
Writing Function Rules
Writing Function RulesWriting Function Rules
Writing Function RulesBitsy Griffin
 
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-newRafika Dewi
 

Viewers also liked (20)

If You Give a Mongolian Some Money
If You Give a Mongolian Some MoneyIf You Give a Mongolian Some Money
If You Give a Mongolian Some Money
 
Robert Ng Resume 2016
Robert Ng Resume 2016Robert Ng Resume 2016
Robert Ng Resume 2016
 
Design driven innovation - Turkey Innovation Week 20151204
Design driven innovation - Turkey Innovation Week 20151204Design driven innovation - Turkey Innovation Week 20151204
Design driven innovation - Turkey Innovation Week 20151204
 
Cac – uni papua at banda aceh
Cac – uni papua at banda aceh Cac – uni papua at banda aceh
Cac – uni papua at banda aceh
 
Air pollution
Air pollutionAir pollution
Air pollution
 
Integrative Destination Management - Cooperation
Integrative Destination Management - CooperationIntegrative Destination Management - Cooperation
Integrative Destination Management - Cooperation
 
KB 3 - Manajemen Kebidanan Pada Ibu Nifas
KB 3 - Manajemen Kebidanan Pada Ibu NifasKB 3 - Manajemen Kebidanan Pada Ibu Nifas
KB 3 - Manajemen Kebidanan Pada Ibu Nifas
 
Telemetry Onboarding
Telemetry OnboardingTelemetry Onboarding
Telemetry Onboarding
 
Bersalin
BersalinBersalin
Bersalin
 
Improving the business environment and access to finance for SMEs
Improving the business environment and access to finance for SMEsImproving the business environment and access to finance for SMEs
Improving the business environment and access to finance for SMEs
 
[2016 K-global 스마트디바이스톤] inSpot
[2016 K-global 스마트디바이스톤] inSpot[2016 K-global 스마트디바이스톤] inSpot
[2016 K-global 스마트디바이스톤] inSpot
 
CSR Activity in Hotel Industry
CSR Activity in Hotel IndustryCSR Activity in Hotel Industry
CSR Activity in Hotel Industry
 
10 stages linear arrow showing the process flow direction slide shop powerpoi...
10 stages linear arrow showing the process flow direction slide shop powerpoi...10 stages linear arrow showing the process flow direction slide shop powerpoi...
10 stages linear arrow showing the process flow direction slide shop powerpoi...
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Visit Saimaa 2016
Visit Saimaa 2016Visit Saimaa 2016
Visit Saimaa 2016
 
Project functionsc++
Project functionsc++Project functionsc++
Project functionsc++
 
Future Proofing Your Portfolio
Future Proofing Your PortfolioFuture Proofing Your Portfolio
Future Proofing Your Portfolio
 
Writing Function Rules
Writing Function RulesWriting Function Rules
Writing Function Rules
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new
217942623 sop-rawat-gabung-ibu-dan-bayi-sehat-new
 

Similar to C program to demonstrate static function

Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
C basics
C basicsC basics
C basicsMSc CST
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
Functions in c
Functions in cFunctions in c
Functions in cInnovative
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
C programming function
C  programming functionC  programming function
C programming functionargusacademy
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)mshoaib15
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programmingPrabhu Govind
 

Similar to C program to demonstrate static function (20)

Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
C basics
C basicsC basics
C basics
 
7 functions
7  functions7  functions
7 functions
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C programming function
C  programming functionC  programming function
C programming function
 
Tu1
Tu1Tu1
Tu1
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)
 
Intro to c programming
Intro to c programmingIntro to c programming
Intro to c programming
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

C program to demonstrate static function

  • 1. Mohammed Sikander Technical Lead CranesVarsity (www.cranesvarsity.com) Mohammed.sikander@cranessoftware.com
  • 2. int countNodes( Node *root) { if(root == NULL) return 0; int leftNodes = countNodes(root->left); int rightNodes = countNodes(root->right); return leftNodes + rightNodes + 1; //+1 for current node }
  • 3. int countLeaf( Node *root) { if(root == NULL) return 0; if(root->left == NULL && root->right == NULL) return 1; int leftLeafNodes = countLeaf(root->left); int rightLeafNodes = countLeaf(root->right); return leftLeafNodes + rightLeafNodes; }
  • 4. int calculateHeight( Node *root) { if(root == NULL) return 0; int leftHeight = calculateHeight(root->left); int rightHeight = calculateHeight (root->right); return max(leftHeight , rightHeight) + 1; }
  • 5. FILE1.C int x = 5; void print( ) int main( ) { print( ); printf(“Main x = %d n”,x); } FILE2.C extern int x; void print( ) { printf(“Print : x = %d n”,x); }
  • 6. FILE1.C extern int x; void print( ); int main( ) { printf(“Main x = %d n”,x); print( ); } FILE2.C int x = 5; void print( ) { printf(“Print : x = %d n”,x); }
  • 7. Learning : We require one definition and a declaration in other file(s). It does not matter which file contains the definition.
  • 8. FILE1.C int x = 8; void print( ); int main( ) { printf(“Main x = %d n”,x); print( ); } FILE2.C int x = 5; void print( ) { printf(“Print : x = %d n”,x); }
  • 9.  Multiple Definition Error.  An external declaration for an object is a definition if it has an initializer (Refer K&R A10.2 ).  As both have initialization, both are definition.  We will get Linker Error (not a compile-time error)
  • 10. FILE1.C static int x; void print( ); int main( ) { printf(“Main x = %d n”,x); print( ); } FILE2.C int x = 5; void print( ) { printf(“Print : x = %d n”,x); }
  • 11.  X in file1 has internal linkage and is not visible during linking of multiple files.  No error of multiple definition.  File1 will access the variable x defined in file1, as it is not initialized, the default value is 0.  File2 will access the variable x defined in file2, whose value is 5
  • 12. FILE1.C static int x = 8; void print( ); int main( ) { extern int x; printf(“Main x = %d n”,x); print( ); } Output is 8. Extern says that the variable is defined externally, within the same file / other file. As an external definition is found, it refers to it.
  • 13. FILE1.C int x ; void print( ); int main( ) { printf(“Main x = %d n”,x); print( ); } FILE2.C int x = 5; void print( ) { printf(“Print : x = %d n”,x); }
  • 14.  An external object declaration that does not have an initializer, and does not contain the extern specifier, is a tentative definition  If a definition for an object appears , any tentative definitions are treated merely as redundant declarations. If no definition for the object appears, all its tentative definitions become a single definition with initializer 0.  The declaration of x in file1 is tentative definition;  As the definition for x is found in file2, x in file1 is treated as declaration only.
  • 15. FILE1.C int x ; void print( ); int main( ) { printf(“Main x = %d n”,x); print( ); printf(“Main x = %d n”,x); } FILE2.C int x; void print( ) { x = 5; printf(“Print : x = %d n”,x); }
  • 16.
  • 17. FILE1.C int arr[5] = {2,5,7}; void print( ); int main( ) { print( ); } FILE2.C extern int arr[ ]; void print( ) { printf(“ %d “ , arr[0] ); }
  • 18. FILE1.C int arr[5] = {2,5,7}; void print( ); int main( ) { print( ); } FILE2.C extern int *arr; void print( ) { printf(“ %d “ , arr[0] ); }
  • 19. FILE1.C int arr[5]; void print( ); int main( ) { print( ); } FILE2.C extern int arr[ ]; void print( ) { printf(“ %d “ , sizeof(arr) ); }
  • 20. FILE1.C int arr[5] = {2 , 5 , 8}; void print(int arr[]); int main( ) { print( arr ); } FILE2.C void print(int arr[] ) { printf(“ %d “ , sizeof(arr) ); }
  • 21. FILE1.C int arr[5] = {2 , 5 , 8}; void print(int arr[]); int main( ) { print( arr ); } FILE2.C void print(int *arr ) { printf(“ %d “ , arr[0] ); }
  • 22. FILE1.C char arr[25] = “RADHA”; void print( ); int main( ) { print( ); } FILE2.C extern char *arr; void print( ) { printf(“ %s “ , arr); }
  • 23.  Draw an Expression Tree for the given expression and traverse in inorder,preorder and postorder.  A + B * C  A * (B + C)
  • 24. int *pi; char *pc; short int *psi; printf(“ %d n”,sizeof(pi)); printf(“ %d n”,sizeof(pc)); printf(“ %d n”,sizeof(psi)); int *pi; char *pc; short int *psi; printf(“ %d n”,sizeof(*pi)); printf(“ %d n”,sizeof(*pc)); printf(“ %d n”,sizeof(*psi));
  • 25. int *pi = (int *)2000; char *pc = (char *)2000; pi++; pc++; printf(“ %u %u “ , pi , pc);
  • 26. int x = 0x1234; char c = x; printf(“ %x “ , c);
  • 27. const int x = 10; 1.int * const ptr1 = &x; 2.int const * ptr2 = &x; 3.const int * ptr3 = &x;
  • 28. void update(int *p) { *p = *p + 5; } int main( ) { int x = 10; int *ptr = &x; update(ptr); printf(“x = %d “ , x); }
  • 29. void update(int *p) { p = p + 1; } int main( ) { int arr[ ] = {10 , 12 , 25 , 45}; int *ptr = arr; update(ptr); printf(“*ptr = %d “ , *ptr); }
  • 30. void update(int *p) { *p = *p + 1; } int main( ) { int arr[ ] = {10 , 12 , 25 , 45}; int *ptr = arr; update(ptr); printf(“*ptr = %d “ , *ptr); }
  • 31. void update(char *str) { str = “Devendra”; } int main( ) { char *name = “Nimisha”; update(name); printf(“ %s n” , name); }
  • 32. void update(char *str) { str[0] = ‘H’; } int main( ) { char name[ ] = “Nimisha”; char *ptr = name; update(ptr); printf(“ %s n” , name); }
  • 33. void update(char *str) { *++str = ‘a’; } int main( ) { char name[ ] = “Nimisha”; char *ptr = name; update(ptr); printf(“ %s n” , name); }
  • 34. int main( ) { char names[] [10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; printf(“ %__ “ , *(names + 2) + 3); printf(“ %__ “ , **(names + 2) + 3); }
  • 35. int main( ) { char names[][10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; 1. printf(“ %s “ , *(++names)); 2. printf(“ %s “ , ++*(names)); 3. printf(“ %c “ , ++**(names)); }
  • 36. int main( ) { char *names[10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; 1. printf(“ %s “ , *(++names)); 2. printf(“ %s “ , ++*(names)); 3. printf(“ %c “ , ++**(names)); }
  • 37. struct Student { int id; char name[20]; }; int main( ) { struct Student s1 = {1 , “Ayushi”}; struct Student s2 = {2 , “Ayushi”}; if(s1.name == s2.name) printf(“Equal”); else printf(“Not Equal”); }
  • 38. char *names[ ] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”}; printf(“ %d “ , sizeof(names)); printf(“ %d “ , sizeof(names[0])); char names[ ][10] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”}; printf(“ %d “ , sizeof(names)); printf(“ %d “ , sizeof(names[0]));
  • 39. void display( char *names[ ]) { printf(“Display : %d n “ , sizeof(names)); } int main( ) { char *names[ ] = {“Nimisha”,”Devender”,”Vikram”,”Balwant”}; printf(“Main : %d n“ , sizeof(names)); display( names ); }
  • 40. static int x = 5; int main( ) { int x; printf(“x = %d n”,x); }
  • 41. static int x = 5; int main( ) { extern int x; printf(“x = %d n”,x); }
  • 42. int a = 5; int b; static int c = 7; static int d; int main( ) { } • Mention the memory segments of variables after compiling (.o file) and after linking (a.out) • What is the difference between a and c. • Use nm utility to view the memory segments $gcc –c file.c $nm file.o $gcc file.c $nm ./a.out
  • 43. void func( ); int x; int main( ) { x = 5; func( ); printf(“x = %d “ , x); } int x; void func( ) { x = 10; }
  • 44. [sikander@localhost ~]$ gcc -c f1.c [sikander@localhost ~]$ gcc -c f2.c [sikander@localhost ~]$ nm f1.o U func 00000000 T main U printf 00000004 C x [sikander@localhost ~]$ nm f2.o 00000000 T func 00000004 C x [sikander@localhost ~]$ gcc f1.o f2.o [sikander@localhost ~]$ nm a.out 080495ac B x
  • 45. void func( ); int x = 5; int main( ) { func( ); printf(“x = %d “ , x); } int x = 10; void func( ) { x++; }
  • 46.  [sikander@localhost ~]$ gcc -c f1.c  [sikander@localhost ~]$ gcc -c f2.c  [sikander@localhost ~]$ nm f1.o  00000000 D x  [sikander@localhost ~]$ nm f2.o  00000000 D x  [sikander@localhost ~]$ gcc f1.o f2.o  f2.o(.data+0x0): multiple definition of `x'  f1.o(.data+0x0): first defined here  collect2: ld returned 1 exit status
  • 47. C C B C D D D D Multiple Definition d d No Conflict, two different variables b b No Conflict, two different variables d b No Conflict, two different variables b d No Conflict, two different variables b D No Conflict, two different variables
  • 48. int x ; //C int main( ) { printf(“Main &x= %p” , &x); printf(“x = %d n”, x); func( ); } int x ; //C void func( ) { printf(“Func &x= %p” , &x); printf(“x = %d n”, x); } int x ; //C int main( ) { printf(“Main &x= %p” , &x); printf(“x = %d n”, x); func( ); } int x = 5 ; //D void func( ) { printf(“Func &x= %p” , &x); printf(“x = %d n”, x); }
  • 49. void func( ); int x = 5; //D int main( ) { printf(“Main &x= %p” , &x); printf(“x = %d n”, x); func( ); } int x = 10; //D void func( ) { printf(“Func &x= %p” , &x); printf(“x = %d n”, x); } void func( ); static int x = 5; //d int main( ) { printf(“Main &x= %p” , &x); printf(“x = %d n”, x); func( ); } int x = 10; //D void func( ) { printf(“Func &x= %p” , &x); printf(“x = %d n”, x); }
  • 50. const int x = 10; //Read Only int main( ) { const int y = 5; //Stack }
  • 51. const int x = 10; //Read Only int main( ) { const int y = 5; //Stack printf(“Enter the value for local const variable : “); scanf(“ %d”,&y); printf(“Local Const = %d n” , y); printf(“Enter the value for global const variable : “); scanf(“ %d”,&x); printf(“Global Const = %d n”,x); } [sikander@localhost ~]$ ./a.out Enter the value for local const variable : 89 Local Const = 89 Enter the value for global const variable : 6 Segmentation fault
  • 52.  [sikander@localhost ~]$ nm f1.o  00000000 t display  0000000a T main  00000005 T print static void display() { } void print() { } int main( ) { display( ); print( ); }