SlideShare una empresa de Scribd logo
1 de 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( );
}

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Destacado

Robert Ng Resume 2016
Robert Ng Resume 2016Robert Ng Resume 2016
Robert Ng Resume 2016
Robert Ng
 
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
Uwes Chaeruman
 
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
 
Writing Function Rules
Writing Function RulesWriting Function Rules
Writing Function Rules
Bitsy 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-new
Rafika Dewi
 

Destacado (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 a Cquestions

C basics
C basicsC basics
C basics
MSc CST
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 

Similar a Cquestions (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
 

Último

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Cquestions

  • 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( ); }