SlideShare a Scribd company logo
C questions
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

PPTX
PDF
Implementing string
PPT
Cquestions
PDF
Implementation of c string functions
PPTX
Function basics
PDF
Stl algorithm-Basic types
PDF
Pointer level 2
PDF
Understanding storage class using nm
Implementing string
Cquestions
Implementation of c string functions
Function basics
Stl algorithm-Basic types
Pointer level 2
Understanding storage class using nm

What's hot (20)

PPTX
Pointer level 2
PDF
C++ Question on References and Function Overloading
PDF
C++ Programming - 1st Study
PPTX
4. chapter iii
PPTX
3. chapter ii
PDF
Data Structures Practical File
PPTX
Double linked list
PPTX
Double linked list
PDF
C++ Programming - 4th Study
DOCX
C++ file
DOCX
Data Structures Using C Practical File
PDF
C Prog - Array
DOCX
Basic Programs of C++
PDF
C++ programs
DOCX
SaraPIC
PDF
C++ Programming - 14th Study
PPSX
C programming array & shorting
PDF
C++ Programming - 2nd Study
PDF
C Prog. - Structures
Pointer level 2
C++ Question on References and Function Overloading
C++ Programming - 1st Study
4. chapter iii
3. chapter ii
Data Structures Practical File
Double linked list
Double linked list
C++ Programming - 4th Study
C++ file
Data Structures Using C Practical File
C Prog - Array
Basic Programs of C++
C++ programs
SaraPIC
C++ Programming - 14th Study
C programming array & shorting
C++ Programming - 2nd Study
C Prog. - Structures
Ad

Viewers also liked (20)

PDF
8_Diversity and antimicrobial activity of fungal endophyte communities associ...
PDF
Kevin A Carter Disruptive Inclusion (Diversity Inclusion Innovation) Presenta...
PDF
Kti siti sariandi
PPTX
6 группа игры и игрушки
PDF
Fiscal Regime in the Canary Islands by E&Y (Canary Islands Hub)
PDF
5 Reasons & 5 Opportunities to do business from the Canary Islands Hub
PPT
спрощення в групах приголосних
PDF
305965972 aloksan-glucose-n-trombosit
PPTX
Kel 5
DOCX
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN PADA BAYI NY. ”I” DENGAN BAYI...
DOCX
PPTX
Infeksi Puerperalis
PPTX
Protocols
DOC
CephaloPelvicDisporportion (pembimbing : dr. Arie Widiyasa, spOG)
PPTX
Television trends in Tamil Satellite Channels an analysis
PPT
Ppt on case study of near misses in singhania textile mills
PPTX
Konsep dan Asuhan Keperawatan Ibu Hamil Normal dan Komplikasi
PDF
Diversity, Inclusion and Innovation Strategic Leadership Assessment Tool
PPT
TOILET AND SUTURE
8_Diversity and antimicrobial activity of fungal endophyte communities associ...
Kevin A Carter Disruptive Inclusion (Diversity Inclusion Innovation) Presenta...
Kti siti sariandi
6 группа игры и игрушки
Fiscal Regime in the Canary Islands by E&Y (Canary Islands Hub)
5 Reasons & 5 Opportunities to do business from the Canary Islands Hub
спрощення в групах приголосних
305965972 aloksan-glucose-n-trombosit
Kel 5
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN PADA BAYI NY. ”I” DENGAN BAYI...
Infeksi Puerperalis
Protocols
CephaloPelvicDisporportion (pembimbing : dr. Arie Widiyasa, spOG)
Television trends in Tamil Satellite Channels an analysis
Ppt on case study of near misses in singhania textile mills
Konsep dan Asuhan Keperawatan Ibu Hamil Normal dan Komplikasi
Diversity, Inclusion and Innovation Strategic Leadership Assessment Tool
TOILET AND SUTURE
Ad

Similar to C questions (20)

DOCX
PDF
C for Java programmers (part 3)
PDF
Basic C Programming Lab Practice
PPTX
Introduction to c
PDF
ANSI C REFERENCE CARD
PDF
The best every notes on c language is here check it out
PDF
Slide set 6 Strings and pointers.pdf
PPTX
UNIT 6structureofcprogrammingforppt.pptx
PPTX
C programm.pptx
PPTX
C programming(part 3)
PPTX
C LANGUAGE.pptx
PPTX
C LANGUAGE.pptx
PPTX
programming in C and Datastructures deepdive
PPT
PDF
programming in C & Data structures an easy approach
ODT
Tut1
PPT
C Programming Intro.ppt
 
PPTX
Programming in C
PPTX
Programming in C
C for Java programmers (part 3)
Basic C Programming Lab Practice
Introduction to c
ANSI C REFERENCE CARD
The best every notes on c language is here check it out
Slide set 6 Strings and pointers.pdf
UNIT 6structureofcprogrammingforppt.pptx
C programm.pptx
C programming(part 3)
C LANGUAGE.pptx
C LANGUAGE.pptx
programming in C and Datastructures deepdive
programming in C & Data structures an easy approach
Tut1
C Programming Intro.ppt
 
Programming in C
Programming in C

More from mohamed sikander (7)

PPTX
C++ 11 range-based for loop
PDF
Implementing stack
PDF
Polymorphism
PDF
Inheritance and polymorphism
PDF
Container adapters
PDF
Operator overloading
PDF
Static and const members
C++ 11 range-based for loop
Implementing stack
Polymorphism
Inheritance and polymorphism
Container adapters
Operator overloading
Static and const members

Recently uploaded (20)

PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Nekopoi APK 2025 free lastest update
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Cost to Outsource Software Development in 2025
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PPTX
assetexplorer- product-overview - presentation
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
17 Powerful Integrations Your Next-Gen MLM Software Needs
Navsoft: AI-Powered Business Solutions & Custom Software Development
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms II-SECS-1021-03
Why Generative AI is the Future of Content, Code & Creativity?
Complete Guide to Website Development in Malaysia for SMEs
Nekopoi APK 2025 free lastest update
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Patient Appointment Booking in Odoo with online payment
Adobe Illustrator 28.6 Crack My Vision of Vector Design
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Cost to Outsource Software Development in 2025
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
assetexplorer- product-overview - presentation
Digital Systems & Binary Numbers (comprehensive )
Design an Analysis of Algorithms I-SECS-1021-03
iTop VPN Free 5.6.0.5262 Crack latest version 2025

C questions

  • 2. 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));
  • 3. int *pi = (int *)2000; char *pc = (char *)2000; pi++; pc++; printf(“ %u %u “ , pi , pc);
  • 4. int x = 0x1234; char c = x; printf(“ %x “ , c);
  • 5. const int x = 10; 1.int * const ptr1 = &x; 2.int const * ptr2 = &x; 3.const int * ptr3 = &x;
  • 6. void update(int *p) { *p = *p + 5; } int main( ) { int x = 10; int *ptr = &x; update(ptr); printf(“x = %d “ , x); }
  • 7. void update(int *p) { p = p + 1; } int main( ) { int arr[ ] = {10 , 12 , 25 , 45}; int *ptr = arr; update(ptr); printf(“*ptr = %d “ , *ptr); }
  • 8. void update(int *p) { *p = *p + 1; } int main( ) { int arr[ ] = {10 , 12 , 25 , 45}; int *ptr = arr; update(ptr); printf(“*ptr = %d “ , *ptr); }
  • 9. void update(char *str) { str = “Devendra”; } int main( ) { char *name = “Nimisha”; update(name); printf(“ %s n” , name); }
  • 10. void update(char *str) { str[0] = ‘H’; } int main( ) { char name[ ] = “Nimisha”; char *ptr = name; update(ptr); printf(“ %s n” , name); }
  • 11. void update(char *str) { *++str = ‘a’; } int main( ) { char name[ ] = “Nimisha”; char *ptr = name; update(ptr); printf(“ %s n” , name); }
  • 12. int main( ) { char names[] [10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; printf(“ %__ “ , *(names + 2) + 3); printf(“ %__ “ , **(names + 2) + 3); }
  • 13. int main( ) { char names[][10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; 1. printf(“ %s “ , *(++names)); 2. printf(“ %s “ , ++*(names)); 3. printf(“ %c “ , ++**(names)); }
  • 14. int main( ) { char *names[10]={“OBAMA”,”PUTIN”,”MODI”,”CAMEROON”}; 1. printf(“ %s “ , *(++names)); 2. printf(“ %s “ , ++*(names)); 3. printf(“ %c “ , ++**(names)); }
  • 15. 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”); }
  • 16. 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]));
  • 17. 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 ); }
  • 18. static int x = 5; int main( ) { int x; printf(“x = %d n”,x); }
  • 19. static int x = 5; int main( ) { extern int x; printf(“x = %d n”,x); }
  • 20. 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
  • 21. void func( ); int x; int main( ) { x = 5; func( ); printf(“x = %d “ , x); } int x; void func( ) { x = 10; }
  • 22. [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
  • 23. void func( ); int x = 5; int main( ) { func( ); printf(“x = %d “ , x); } int x = 10; void func( ) { x++; }
  • 24.  [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
  • 25. 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
  • 26. 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); }
  • 27. 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); }
  • 28. const int x = 10; //Read Only int main( ) { const int y = 5; //Stack }
  • 29. 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
  • 30.  [sikander@localhost ~]$ nm f1.o  00000000 t display  0000000a T main  00000005 T print static void display() { } void print() { } int main( ) { display( ); print( ); }