C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - General Questions (Q.No. 2)
2.
What are the types of linkages?
Answer: Option
Explanation:
External Linkage-> means global, non-static variables and functions.
Internal Linkage-> means static variables and functions with file scope.
None Linkage-> means Local variables.
Internal Linkage-> means static variables and functions with file scope.
None Linkage-> means Local variables.
Discussion:
95 comments Page 6 of 10.
Purnima said:
1 decade ago
Can you give me the brief explanation about linkages and what are the storage classes?
Sumanth said:
1 decade ago
Thanx Dixin
DixN said:
1 decade ago
The reason is
x=5
++x means x=6
then ++x means x=7
then only it will start to add
z=x+x
but at the end x=7
therefore
z=7+7
ie z=14 is the answer
x=5
++x means x=6
then ++x means x=7
then only it will start to add
z=x+x
but at the end x=7
therefore
z=7+7
ie z=14 is the answer
Gaurav said:
1 decade ago
x= 5;
z = ++x + ++x ;
cout<<z;
why does this display 14 , instead of 13 ?
z = ++x + ++x ;
cout<<z;
why does this display 14 , instead of 13 ?
Saikiran said:
1 decade ago
What Prathyusha said is correct. That can be easily understood using this program.
#include<stdio.h>
int main()
{
printf("\n%d",funi());
printf("\n%d",funi());
printf("\n%d",funi());
printf("\n%d",funj());
printf("\n%d",funj());
printf("\n%d",funj());
//printf("\ni=%d\nj=%d",i,j);
return 0;
}
int funi()
{
int i;
i++;
return i;
}
int funj()
{
static int j;
j++;
return j;
}
output:
1
1
1
1
2
3
#include<stdio.h>
int main()
{
printf("\n%d",funi());
printf("\n%d",funi());
printf("\n%d",funi());
printf("\n%d",funj());
printf("\n%d",funj());
printf("\n%d",funj());
//printf("\ni=%d\nj=%d",i,j);
return 0;
}
int funi()
{
int i;
i++;
return i;
}
int funj()
{
static int j;
j++;
return j;
}
output:
1
1
1
1
2
3
Siri said:
1 decade ago
Good explanation pratyusha, thanq so much.
Ram krishna said:
1 decade ago
I will thank full to Satish Narasimman and Prathyusa, who cleared my doubt.
Rajesh said:
1 decade ago
We declare already a static varible, in derived class we declare one more same static variable as declared first with different value, and call the previous variable,.......then.....Is the out put of program is first variable's value or secon variale's value...
Prathyusha said:
1 decade ago
//SATHISH explanation was correct!..
int main()
{
printf(" %d",root());
printf(" %d",root());
}
int root()
{
static int i;
i++;
return i;
}
BY DEFAULT ,ANY INTEGER OR STATIC INT VARIABLE VALUE IS ZERO.
BUT WHEN EACH TIME THE FUNCTION WAS CALLED ,THE DIFFERENCE OF NORMAL INT AND STATIC INT CAN BE SEEN.
IF THE "i" HERE IS NORMAL INTEGER IT WILL JUST RETURN ALWAYS VALUE "1" ,EVERY TIME IT IS CALLED .
BUT THE STATIC VARIABLE WILL HOLD PREVIOUS VALUES OF "i".EVERY TIME WHEN THE FUNCTION IS CALLED IT WILL THE PREVIOUS VALUES ARE RESTORED.
int main()
{
printf(" %d",root());
printf(" %d",root());
}
int root()
{
static int i;
i++;
return i;
}
BY DEFAULT ,ANY INTEGER OR STATIC INT VARIABLE VALUE IS ZERO.
BUT WHEN EACH TIME THE FUNCTION WAS CALLED ,THE DIFFERENCE OF NORMAL INT AND STATIC INT CAN BE SEEN.
IF THE "i" HERE IS NORMAL INTEGER IT WILL JUST RETURN ALWAYS VALUE "1" ,EVERY TIME IT IS CALLED .
BUT THE STATIC VARIABLE WILL HOLD PREVIOUS VALUES OF "i".EVERY TIME WHEN THE FUNCTION IS CALLED IT WILL THE PREVIOUS VALUES ARE RESTORED.
Prasanth reddy.d said:
1 decade ago
Can static variables be declared before main() ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers