Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this C program compile and run successfully?

Tags:

c

I was asked this in an interview. What will be the result of this program? I confidently said that this will not compile. I said that a is an array name and does not take up any space, so &a should not make any sense, hence this will not compile. but on hands-on, it turns out that compiles as well as runs successfully. Could someone please explain, how this works.

main()    
{
    int a[50];
    &a; // or perhaps the interviewer wanted to know the output of this line..
}
like image 798
xyz Avatar asked Feb 21 '26 10:02

xyz


1 Answers

The &a; line just computes the address of the array a, and silently discards it.

like image 53
Graham Borland Avatar answered Feb 23 '26 23:02

Graham Borland