1,777 views
12 votes
12 votes
#include <stdio.h>
int foo(int a[100])
{
    return sizeof(a);
}
int main()
{
    int a[10];
    printf("%d", foo(a));
}

What will be the output of the above code ignoring any compiler warnings and assuming sizeof(int) as 4 when run on a 64 bit machine?

1 Answer

Best answer
19 votes
19 votes

In C programming language, array parameters are treated as pointers .So here we  are passing base address of array a through function foo().

 So the expression sizeof(a) will become sizeof (int *) which results in 4 or 8 depending on machine 32 bit or 64 bit.

Here it is mentioned that on 64 bit machine so it will return 8.

selected by
Answer:

Related questions

3 votes
3 votes
4 answers
1
Arjun asked Oct 18, 2016
775 views
What will be the output of the following code?#include <stdio.h int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }
2 votes
2 votes
5 answers
2
Arjun asked Oct 18, 2016
1,574 views
The value returned by the following code is _____int foo() { int a[] = { 10, 20, 30, 40, 50, 60 }; int *p = &a , *q = &a[5] ; return q-p; }
3 votes
3 votes
2 answers
3
7 votes
7 votes
3 answers
4
Arjun asked Oct 18, 2016
1,591 views
The output of the following C program will be _____#include<stdio.h #define type int type foo(type b) { return b*b; } #undef type #define type float int main() { float a ...