C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 2)
2.
What are the types of linkages?
Internal and External
External, Internal and None
External and None
Internal
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.
Discussion:
96 comments Page 3 of 10.

Lipsha said:   1 decade ago
What are linkages?

Hilal Bhat said:   1 decade ago
what about the following:

int i=5;
printf("%d",(++i + ++i);
it is printing 13.

While as:

int i=5,z;
z=(++i + ++i);
printf("%d",z);
prints 14.

Can anyone explain why?

Sravani said:   1 decade ago
Hey guys x++ + ++x though we are making changes to x that will be updated in register because of optimization it treats both x as same value and makes z=x+x;

x++=value is incremented after the statement completes and x=2.
After ++x= pre inc so x in inc and x value is 3 and is stored in only one place now addition happens z=x+x,z=3+3=6;

But if you use volatile in front of int x; then it will give z=5;

Sandeep said:   1 decade ago
When x=2,
if z=x++ + ++x.
Then z=?

Saiba Murmu said:   1 decade ago
It gives result according to the compiler.

GCC compiler gives Result: 9.

TCC compiler gives Result: 8.

Explanation:

In GCC compiler, variables are stored in stack memory area. First value 4 is stored after incrementing by the pre-increment operator then second value 5 is stored after increment. So the Result is 9.

But in case of TCC compiler first value 4 is stored in stack then before increment the second value of x=4 is stored. So the Result is 8.

Bhavani said:   1 decade ago
@Moumita.

When x=5 then,

Z=++x + ++x;

Is printing 14 not 13.
I checked it guys,

x = 7 at last, Because a value of a variable(x) vl hold the latest value that's being stored in the memory(i.e) 7.

So z = 7+7 = 14.

Mounika said:   1 decade ago
13 because here first x = 5.
Then ++x = 6(pre increment).

Now x = 6.
Then ++x = 7.

So z = ++x + ++x.
z = 6+7 => 13.

Moumita said:   1 decade ago
Guys please check this once more.

When x =5 then,

Z=++x + ++x;

Is printing 13 not 14....

So what is the actual explanation?

Vams said:   1 decade ago
@Aliya.

C compiler does parsing (reading and evaluating) from left to right of each line of code. That is purely related to compiler design(cd) topic for further details refer cd of C language.

Anil said:   1 decade ago
#include <stdio.h>
int main()
{
int i = 2;
int j = ++i + i;
printf("%d\n", j);
}

Output = 6.

How is it possible? Please give me an explanation.


Post your comments here:

Your comments will be displayed after verification.