SlideShare a Scribd company logo
Complicated Declarations In C
By Rahul Budholiya
Founder Lunaplena Apps
rahulbudholiya.blogspot.com
www.linkedin.com/pub/rahul-budholiya/34/53/b35
www.facebook.com/rahul.budholiya.dev
Declaration And Definition
Definition:
Function:
int add(int a,int b)
{
retrun a+b;
}
Variable:
int a;
User Defined data
type:
union student
{
int a;
char c[2];
};
Declaration:
Function:
int add(int,int);
extern int add(int,int);
Variable:
extern int a;
User Defined data
type:
union student;
extern union student;
Declaration of Pointers.
General Syntax:
[name of data type] *<variable_name>;
Here [name of data type] is data type of variable, address
of which this pointer can contain.
But it is not as simple as, above syntax is seems like.
All the keywords placed before โ€˜*โ€™ does not affect
properties (they define properties of variable which can be
pointed by this pointer) of pointer variable. If we need to
affect properties of pointer variable all keywords must be
placed after * sign(but there are exceptions like far,huge
and near).
Declaration of Pointers.
There are pointer type in c, like int * is a type of int
pointer.
If we assume int * is a type, and we know that we can
create pointers of any type by writing โ€˜[type name] * โ€˜.
So if we write int* * then it will create pointer of a int
pointer.
We can define a pointer to any other pointer in c.
Keywords and operators that
affects declarations
Const Phenomenon
Const is a keyword which defines a read only variable.
Variable declared with const keyword can only be assigned
a value once in lifetime.
Syntax:
const type <variable_name>;
Type const <variable_name>;
Ex:-
const int a;
int const a;
Const Phenomenon
What is the difference between following two declarations ?
const int *p;
int const *p;
Answer:
There is no difference, both refers to same meaning.
Const Phenomenon
What is the difference between following two declarations ?
const int *p;
int * const p;
Answer:
First is a pointer to a constant int(*p=10 is wrong). And
second is a constant pointer to int.(p=10 is wrong).
near,far and huge
near,far and huge pointers
near,far and huge are used with pointers.
โ€ขThese keywords were introduced to support memory
segmentation.
โ€ขSize of a near pointer is 2 bytes, and size of huge
and far pointers is 4 bytes.
โ€ขNear far and huge pointers only supported by
Borland tc under dos, 32 bit platforms like window,
linux and unix does not support these keywords,
there are all pointers are 32 bit.
near,far and huge pointers
Which is the following is a near pointer ?
char near * far *ptr;
char near * huge *ptr2;
char far * huge* ptr3;
Answer:
No one is near pointer;
Using () operator in declarations.
Using () operator in declarations.
Like any other instruction of c, part of declarative
instruction contained by () operator executes separately,
and () operator defined by inner most โ€˜()โ€™(level) executes
first and then one who has higher level of nesting.
Syntex:
Exp1(Exp2โ€ฆ.(ExpN <variable_name>));
Exp1 ,Expโ€ฆExpN are all sub expressions of a declarative
statement.
Using [] operator in declarations
[] operator in a declaration define size of memory by
multiplying size of data type specified in statement with the
size specified in [] operator.
But what will happen with this memory size it depends on
declaration.
Using [] operator in declarations
Observe following two declarations.
int *p[10];
int (*p)[10];
First one allocates 20 bytes and second one allocates two bytes.
First is a array of 10 int pointers.
And second is a pointer to a block which has size of 20 bytes.
In first statement [10] will going to be read first by
compiler. So compiler thought p as a array of 10 elements
and then it looks up for type of these elements which it
finds int *.
In Second statement () will executes first by compiler, so
compiler thought p as a pointer and then it looks up for
type of this pointer which it finds int [10].
Use of () And [] in function pointer declarations.
Use of () And [] in function pointer declarations.
We can have pointers to functions in c.
Read following declaration.
int *p(int,int);
Above is a declaration. Of a function named p with two int
parameters and int * as return type.
How can we declare a pointer to this function ?
Answer:
int * (*p)(int,int);
Now p is a pointer to a function which has two int parameters
and int *as return type.
Use of () and [] in function pointer declarations.
Now, how we can declare a array of pointers of following function
int *p(int,int);
int (*(p[10]))(int,int);
In above declaration p is a array of 10 pointers of a function which
has two int parameters and int * as return type.
Now you can see, above is not the general declaration syntax of
pointers, as we saw earlier
[name of data type] *<variable_name>;
Now finally we came to some real complicated declarations.
Can you read following declaration ?
void (*f())(void(*)(int *,void**),int(*)
(void**,int*));Answer:
Yes
Rules to read declaration in c
1. Start with the inner most () containing variable
name.
2. Read the declarations clock wise. Read left first
in the same () and then right.
3. Read from inner most () to outer most().
Rules to read declarations in c.
Char ( * ( * f () ) [] ) ();
1
2
3
4
5
6
Rules to read declarations in c.
Char ( * ( * f () ) [] ) ();
F is function which returns a pointer to an array of pointers to
a function which returns an char.
Can you read following declaration ?
void (*f())(void(*)(int *,void**),int(*)
(void**,int*));Answer:
Yes
In above declaration f is a function which returns a pointer to a
function which returns nothing and receives two parameters. First
is a pointer to a function which returns nothing but receives two
parameters first is pointer to an int and second is a pointer to a void
pointer. The second parameter is a pointer to a function which
retruns an int an receives two parameters first is pointer to a void
pointer and second is a pointer to a int.
Can you declare a array of pointers of a
function which receives four
parameters all of following type and
returns following pointer.
void (*f())(void(*)(int *,void**),int(*)
(void**,int*));
Answer:
Do I Look like a fool ?
Now typedef comes in picture.
How typedef works.
What are the types of var1,var2,var3 and var4 in following program ?
#include<stdio.h>
#define character char *
Void main()
{
Typedef char * CHARAT
character var1,var2;
CHARAT var3,var4;
}
Answer:
In above code var1,var3,var4 are pointers to char and
var2 is char variable.
Will following code compile?
typedef struct
{
int data;
NODEPTR next;
} *NODEPTR;
Answer: No
A typedef declaration can not be used until it is defined,
and in following example it not defined when it is used.
Any variable declaration can be
converted by typedef.
typedef int arr[10];
arr a;
typedef int (*p)(int,int);
p func();
struct student Stu1,Stu2;
Stu1 g;
Stu2 b;
Can you declare a array of pointers of a function
which receives four parameters all of following
type and returns following pointer.
void (*f())(void(*)(int *,void**),int(*)
(void**,int*));
Answer:
typedef void (*f())(void(*)(int *,void**),int(*)(void**,int*));
f(*g[10])(f,f,f,f);
Questions
What will be the output of
following program ?
#include<stdio.h>
int main()
{
char near * near *ptr1;
char near * far *ptr2;
char near * huge *ptr3;
printf(โ€œ%d %d %dโ€,sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
return 0;
}
Answer: 2,4,4
Will following code compile
without error ?
#include<stdio.h>
structr student;
int main()
{
struct student a;
return 0;
}
struct student
{
int roll;
};
Answer: Above code will compile without any error.
Will following code compile
without error ?
#include<stdio.h>
structr student;
int main()
{
struct student a;
a.roll=10;
Printf(โ€œ%dโ€);
return 0;
}
struct student
{
int roll;
};
Answer: above code will not compile.
Read following declaration.
char (*(*x[3])())[5];
Answer:
x is an array of 3 function pointers, where each pointer points to a
function that returns a pointer to array of 5 chars.
Read following declaration.
void (*f[10])(int,int);
Answer:
f is an array of 10 function pointers, where each pointer points to a
function that receives two ints and returns nothing.
Read following declaration.
int (*ftable[])(void) ={fadd,fsub,fmul,fdiv};
Answer:
Ftable is an array of 5 function pointers which points to the function
fadd(),fsub(),fmul(),fdiv()
Read following declaration.
int ** (*f)(int **,int **(*)(int **,int **));
Answer:
f is a pointer to a function which returns a pointer to int pointer and
receives two parameters . First is a pointer of pointer of int. And
second is a pointer to a function which receives two pointers of int
pointer as parameters and returns a pointer to int pointer.
What do the following declaration means ?
Typedef char *pc;
Typedef pc fpc();
Typedef fpc *pfpc;
Typedef pfpc fpfpc();
Typedef fpfpc *pfpfpc;
Pfpfpc a[10];
pc is a pointer to char.
fpc is a function which returns a pointer to char.
pfpc is a pointer to a function returning pointer to a char.
fpfpc is a function returning pointer to a function returning
pointer to a char.
pfpfpc is a pointer to function returning pointer to a function
returning pointer to char.
pfpfpc a[10] is an array of 10 pointers to a function returning
pointers to functions returning pointer to characters.
All The Best!!!
For more stuff visit
rahulbudholiya.blogspot.com

More Related Content

What's hot

Html
HtmlHtml
Html
Noha Sayed
ย 
String functions and operations
String functions and operations String functions and operations
String functions and operations
Mudasir Syed
ย 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
shaibal sharif
ย 
Vi Editor
Vi EditorVi Editor
Vi Editor
Shiwang Kalkhanda
ย 
Python programming : Threads
Python programming : ThreadsPython programming : Threads
Python programming : Threads
Emertxe Information Technologies Pvt Ltd
ย 
Operators php
Operators phpOperators php
Operators php
Chandni Pm
ย 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!
Noelle Daley
ย 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
ย 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
PriyankaC44
ย 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in java
Umamaheshwariv1
ย 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
ย 
String In C Language
String In C Language String In C Language
String In C Language
Simplilearn
ย 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
ย 
Ternary operator
Ternary operatorTernary operator
Ternary operator
Hitesh Kumar
ย 
Linux: LVM
Linux: LVMLinux: LVM
Linux: LVM
Michal Sedlak
ย 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
ย 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
ย 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
ย 
Python3 (boto3) for aws
Python3 (boto3) for awsPython3 (boto3) for aws
Python3 (boto3) for aws
Sanjeev Kumar Jaiswal
ย 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
bhatvijetha
ย 

What's hot (20)

Html
HtmlHtml
Html
ย 
String functions and operations
String functions and operations String functions and operations
String functions and operations
ย 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
ย 
Vi Editor
Vi EditorVi Editor
Vi Editor
ย 
Python programming : Threads
Python programming : ThreadsPython programming : Threads
Python programming : Threads
ย 
Operators php
Operators phpOperators php
Operators php
ย 
Debugging Python with Pdb!
Debugging Python with Pdb!Debugging Python with Pdb!
Debugging Python with Pdb!
ย 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
ย 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
ย 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in java
ย 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
ย 
String In C Language
String In C Language String In C Language
String In C Language
ย 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
ย 
Ternary operator
Ternary operatorTernary operator
Ternary operator
ย 
Linux: LVM
Linux: LVMLinux: LVM
Linux: LVM
ย 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
ย 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
ย 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
ย 
Python3 (boto3) for aws
Python3 (boto3) for awsPython3 (boto3) for aws
Python3 (boto3) for aws
ย 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
ย 

Viewers also liked

802.11r Explained.
802.11r Explained. 802.11r Explained.
802.11r Explained.
Ajay Gupta
ย 
3cork and kerry
3cork and kerry3cork and kerry
3cork and kerry
riaenglish
ย 
1 mate5 ecuaciรณn-
1 mate5 ecuaciรณn-1 mate5 ecuaciรณn-
1 mate5 ecuaciรณn-
Papรญas Huiza Oyola
ย 
Leave a mark in history
Leave a mark in historyLeave a mark in history
Leave a mark in history
Raphael Mndalasini
ย 
DMI Light Towers - Operational Manual
DMI Light Towers - Operational ManualDMI Light Towers - Operational Manual
DMI Light Towers - Operational Manual
scottf11
ย 
HealthCare BPO
HealthCare BPOHealthCare BPO
HealthCare BPO
procurementservices
ย 
The Building Blocks of Great Video
The Building Blocks of Great VideoThe Building Blocks of Great Video
The Building Blocks of Great Video
Phil Nottingham
ย 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
Constantin Titarenko
ย 
Theย history of video gamesย goes as far back as the early 1940s
Theย history of video gamesย goes as far back as the early 1940sTheย history of video gamesย goes as far back as the early 1940s
Theย history of video gamesย goes as far back as the early 1940s
Jian Li
ย 
Yesu Nallavar -Testimony of Sister Nirmala
Yesu Nallavar -Testimony of Sister NirmalaYesu Nallavar -Testimony of Sister Nirmala
Yesu Nallavar -Testimony of Sister Nirmala
Raja Venkatesan
ย 
Ciclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scpCiclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scp
Ruth Santana
ย 
What color do you like
What color do you likeWhat color do you like
What color do you like
orncn
ย 
OUTPUT BI - MAKING IT WORK FOR YOU
OUTPUT BI - MAKING IT WORK FOR YOUOUTPUT BI - MAKING IT WORK FOR YOU
OUTPUT BI - MAKING IT WORK FOR YOU
paul ormonde-james
ย 
I did not go to School last Saturday
I did not go to School last SaturdayI did not go to School last Saturday
I did not go to School last Saturday
Sandra MP
ย 
Biopharma Production and Development China 2015
Biopharma Production and Development China 2015 Biopharma Production and Development China 2015
Biopharma Production and Development China 2015
Rita Barry
ย 
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
Rakesh Kumar
ย 
Bailey capรญtulo-6
Bailey capรญtulo-6Bailey capรญtulo-6
Bailey capรญtulo-6
Ricardo DE Oliveira Ribeiro
ย 
Orange Sparkle Ball: Who We Are and What We Do
Orange Sparkle Ball: Who We Are and What We DoOrange Sparkle Ball: Who We Are and What We Do
Orange Sparkle Ball: Who We Are and What We Do
Orange Sparkle Ball, Inc.
ย 
Algebra 2 powerpoint
Algebra 2 powerpointAlgebra 2 powerpoint
Algebra 2 powerpoint
roohal51
ย 
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
MD. SAJJADUL KARIM BHUIYAN
ย 

Viewers also liked (20)

802.11r Explained.
802.11r Explained. 802.11r Explained.
802.11r Explained.
ย 
3cork and kerry
3cork and kerry3cork and kerry
3cork and kerry
ย 
1 mate5 ecuaciรณn-
1 mate5 ecuaciรณn-1 mate5 ecuaciรณn-
1 mate5 ecuaciรณn-
ย 
Leave a mark in history
Leave a mark in historyLeave a mark in history
Leave a mark in history
ย 
DMI Light Towers - Operational Manual
DMI Light Towers - Operational ManualDMI Light Towers - Operational Manual
DMI Light Towers - Operational Manual
ย 
HealthCare BPO
HealthCare BPOHealthCare BPO
HealthCare BPO
ย 
The Building Blocks of Great Video
The Building Blocks of Great VideoThe Building Blocks of Great Video
The Building Blocks of Great Video
ย 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
ย 
Theย history of video gamesย goes as far back as the early 1940s
Theย history of video gamesย goes as far back as the early 1940sTheย history of video gamesย goes as far back as the early 1940s
Theย history of video gamesย goes as far back as the early 1940s
ย 
Yesu Nallavar -Testimony of Sister Nirmala
Yesu Nallavar -Testimony of Sister NirmalaYesu Nallavar -Testimony of Sister Nirmala
Yesu Nallavar -Testimony of Sister Nirmala
ย 
Ciclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scpCiclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scp
ย 
What color do you like
What color do you likeWhat color do you like
What color do you like
ย 
OUTPUT BI - MAKING IT WORK FOR YOU
OUTPUT BI - MAKING IT WORK FOR YOUOUTPUT BI - MAKING IT WORK FOR YOU
OUTPUT BI - MAKING IT WORK FOR YOU
ย 
I did not go to School last Saturday
I did not go to School last SaturdayI did not go to School last Saturday
I did not go to School last Saturday
ย 
Biopharma Production and Development China 2015
Biopharma Production and Development China 2015 Biopharma Production and Development China 2015
Biopharma Production and Development China 2015
ย 
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
Zed-Salesโ„ข - a flagship product of Zed-Axis Technologies Pvt. Ltd.
ย 
Bailey capรญtulo-6
Bailey capรญtulo-6Bailey capรญtulo-6
Bailey capรญtulo-6
ย 
Orange Sparkle Ball: Who We Are and What We Do
Orange Sparkle Ball: Who We Are and What We DoOrange Sparkle Ball: Who We Are and What We Do
Orange Sparkle Ball: Who We Are and What We Do
ย 
Algebra 2 powerpoint
Algebra 2 powerpointAlgebra 2 powerpoint
Algebra 2 powerpoint
ย 
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
On needle settings of tuck stitch fully fashioned,22rib diamond design fully-...
ย 

Similar to Complicated declarations in c

Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
Claus Wu
ย 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
ย 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
Koganti Ravikumar
ย 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
Arpit Meena
ย 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Mohammed Saleh
ย 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
MikialeTesfamariam
ย 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
ย 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
Vikash Dhal
ย 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
Emertxe Information Technologies Pvt Ltd
ย 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
ย 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
ย 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
Umesh Nikam
ย 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
hara69
ย 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
Sowri Rajan
ย 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
Jagan Mohan Bishoyi
ย 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
lavparmar007
ย 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
AaliyanShaikh
ย 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
ย 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
David Livingston J
ย 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
ย 

Similar to Complicated declarations in c (20)

Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
ย 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
ย 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
ย 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
ย 
Lecture 4
Lecture 4Lecture 4
Lecture 4
ย 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
ย 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
ย 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
ย 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
ย 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
ย 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
ย 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
ย 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
ย 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
ย 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
ย 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
ย 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
ย 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
ย 
Frequently asked questions in c
Frequently asked questions in cFrequently asked questions in c
Frequently asked questions in c
ย 
Function Pointer
Function PointerFunction Pointer
Function Pointer
ย 

Recently uploaded

How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
ย 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
ย 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
ย 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
ย 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
ย 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
ย 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
Celine George
ย 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
ย 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
ย 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
ย 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
ย 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
ย 

Recently uploaded (20)

How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
ย 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
ย 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
ย 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
ย 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
ย 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
ย 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
ย 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
ย 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
ย 
How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17How Barcodes Can Be Leveraged Within Odoo 17
How Barcodes Can Be Leveraged Within Odoo 17
ย 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
ย 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
ย 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
ย 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
ย 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
ย 

Complicated declarations in c

  • 1. Complicated Declarations In C By Rahul Budholiya Founder Lunaplena Apps rahulbudholiya.blogspot.com www.linkedin.com/pub/rahul-budholiya/34/53/b35 www.facebook.com/rahul.budholiya.dev
  • 2. Declaration And Definition Definition: Function: int add(int a,int b) { retrun a+b; } Variable: int a; User Defined data type: union student { int a; char c[2]; }; Declaration: Function: int add(int,int); extern int add(int,int); Variable: extern int a; User Defined data type: union student; extern union student;
  • 3. Declaration of Pointers. General Syntax: [name of data type] *<variable_name>; Here [name of data type] is data type of variable, address of which this pointer can contain. But it is not as simple as, above syntax is seems like. All the keywords placed before โ€˜*โ€™ does not affect properties (they define properties of variable which can be pointed by this pointer) of pointer variable. If we need to affect properties of pointer variable all keywords must be placed after * sign(but there are exceptions like far,huge and near).
  • 4. Declaration of Pointers. There are pointer type in c, like int * is a type of int pointer. If we assume int * is a type, and we know that we can create pointers of any type by writing โ€˜[type name] * โ€˜. So if we write int* * then it will create pointer of a int pointer. We can define a pointer to any other pointer in c.
  • 5. Keywords and operators that affects declarations
  • 6. Const Phenomenon Const is a keyword which defines a read only variable. Variable declared with const keyword can only be assigned a value once in lifetime. Syntax: const type <variable_name>; Type const <variable_name>; Ex:- const int a; int const a;
  • 7. Const Phenomenon What is the difference between following two declarations ? const int *p; int const *p; Answer: There is no difference, both refers to same meaning.
  • 8. Const Phenomenon What is the difference between following two declarations ? const int *p; int * const p; Answer: First is a pointer to a constant int(*p=10 is wrong). And second is a constant pointer to int.(p=10 is wrong).
  • 10. near,far and huge pointers near,far and huge are used with pointers. โ€ขThese keywords were introduced to support memory segmentation. โ€ขSize of a near pointer is 2 bytes, and size of huge and far pointers is 4 bytes. โ€ขNear far and huge pointers only supported by Borland tc under dos, 32 bit platforms like window, linux and unix does not support these keywords, there are all pointers are 32 bit.
  • 11. near,far and huge pointers Which is the following is a near pointer ? char near * far *ptr; char near * huge *ptr2; char far * huge* ptr3; Answer: No one is near pointer;
  • 12. Using () operator in declarations.
  • 13. Using () operator in declarations. Like any other instruction of c, part of declarative instruction contained by () operator executes separately, and () operator defined by inner most โ€˜()โ€™(level) executes first and then one who has higher level of nesting. Syntex: Exp1(Exp2โ€ฆ.(ExpN <variable_name>)); Exp1 ,Expโ€ฆExpN are all sub expressions of a declarative statement.
  • 14. Using [] operator in declarations [] operator in a declaration define size of memory by multiplying size of data type specified in statement with the size specified in [] operator. But what will happen with this memory size it depends on declaration.
  • 15. Using [] operator in declarations Observe following two declarations. int *p[10]; int (*p)[10]; First one allocates 20 bytes and second one allocates two bytes. First is a array of 10 int pointers. And second is a pointer to a block which has size of 20 bytes. In first statement [10] will going to be read first by compiler. So compiler thought p as a array of 10 elements and then it looks up for type of these elements which it finds int *. In Second statement () will executes first by compiler, so compiler thought p as a pointer and then it looks up for type of this pointer which it finds int [10].
  • 16. Use of () And [] in function pointer declarations.
  • 17. Use of () And [] in function pointer declarations. We can have pointers to functions in c. Read following declaration. int *p(int,int); Above is a declaration. Of a function named p with two int parameters and int * as return type. How can we declare a pointer to this function ? Answer: int * (*p)(int,int); Now p is a pointer to a function which has two int parameters and int *as return type.
  • 18. Use of () and [] in function pointer declarations. Now, how we can declare a array of pointers of following function int *p(int,int); int (*(p[10]))(int,int); In above declaration p is a array of 10 pointers of a function which has two int parameters and int * as return type. Now you can see, above is not the general declaration syntax of pointers, as we saw earlier [name of data type] *<variable_name>; Now finally we came to some real complicated declarations.
  • 19. Can you read following declaration ? void (*f())(void(*)(int *,void**),int(*) (void**,int*));Answer: Yes
  • 20. Rules to read declaration in c 1. Start with the inner most () containing variable name. 2. Read the declarations clock wise. Read left first in the same () and then right. 3. Read from inner most () to outer most().
  • 21. Rules to read declarations in c. Char ( * ( * f () ) [] ) (); 1 2 3 4 5 6
  • 22. Rules to read declarations in c. Char ( * ( * f () ) [] ) (); F is function which returns a pointer to an array of pointers to a function which returns an char.
  • 23. Can you read following declaration ? void (*f())(void(*)(int *,void**),int(*) (void**,int*));Answer: Yes In above declaration f is a function which returns a pointer to a function which returns nothing and receives two parameters. First is a pointer to a function which returns nothing but receives two parameters first is pointer to an int and second is a pointer to a void pointer. The second parameter is a pointer to a function which retruns an int an receives two parameters first is pointer to a void pointer and second is a pointer to a int.
  • 24. Can you declare a array of pointers of a function which receives four parameters all of following type and returns following pointer. void (*f())(void(*)(int *,void**),int(*) (void**,int*)); Answer: Do I Look like a fool ?
  • 25. Now typedef comes in picture.
  • 26. How typedef works. What are the types of var1,var2,var3 and var4 in following program ? #include<stdio.h> #define character char * Void main() { Typedef char * CHARAT character var1,var2; CHARAT var3,var4; } Answer: In above code var1,var3,var4 are pointers to char and var2 is char variable.
  • 27. Will following code compile? typedef struct { int data; NODEPTR next; } *NODEPTR; Answer: No A typedef declaration can not be used until it is defined, and in following example it not defined when it is used.
  • 28. Any variable declaration can be converted by typedef. typedef int arr[10]; arr a; typedef int (*p)(int,int); p func(); struct student Stu1,Stu2; Stu1 g; Stu2 b;
  • 29. Can you declare a array of pointers of a function which receives four parameters all of following type and returns following pointer. void (*f())(void(*)(int *,void**),int(*) (void**,int*)); Answer: typedef void (*f())(void(*)(int *,void**),int(*)(void**,int*)); f(*g[10])(f,f,f,f);
  • 31. What will be the output of following program ? #include<stdio.h> int main() { char near * near *ptr1; char near * far *ptr2; char near * huge *ptr3; printf(โ€œ%d %d %dโ€,sizeof(ptr1),sizeof(ptr2),sizeof(ptr3)); return 0; } Answer: 2,4,4
  • 32. Will following code compile without error ? #include<stdio.h> structr student; int main() { struct student a; return 0; } struct student { int roll; }; Answer: Above code will compile without any error.
  • 33. Will following code compile without error ? #include<stdio.h> structr student; int main() { struct student a; a.roll=10; Printf(โ€œ%dโ€); return 0; } struct student { int roll; }; Answer: above code will not compile.
  • 34. Read following declaration. char (*(*x[3])())[5]; Answer: x is an array of 3 function pointers, where each pointer points to a function that returns a pointer to array of 5 chars.
  • 35. Read following declaration. void (*f[10])(int,int); Answer: f is an array of 10 function pointers, where each pointer points to a function that receives two ints and returns nothing.
  • 36. Read following declaration. int (*ftable[])(void) ={fadd,fsub,fmul,fdiv}; Answer: Ftable is an array of 5 function pointers which points to the function fadd(),fsub(),fmul(),fdiv()
  • 37. Read following declaration. int ** (*f)(int **,int **(*)(int **,int **)); Answer: f is a pointer to a function which returns a pointer to int pointer and receives two parameters . First is a pointer of pointer of int. And second is a pointer to a function which receives two pointers of int pointer as parameters and returns a pointer to int pointer.
  • 38. What do the following declaration means ? Typedef char *pc; Typedef pc fpc(); Typedef fpc *pfpc; Typedef pfpc fpfpc(); Typedef fpfpc *pfpfpc; Pfpfpc a[10]; pc is a pointer to char. fpc is a function which returns a pointer to char. pfpc is a pointer to a function returning pointer to a char. fpfpc is a function returning pointer to a function returning pointer to a char. pfpfpc is a pointer to function returning pointer to a function returning pointer to char. pfpfpc a[10] is an array of 10 pointers to a function returning pointers to functions returning pointer to characters.
  • 39. All The Best!!! For more stuff visit rahulbudholiya.blogspot.com