C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 3)
3.
Point out the error in the following program.
#include<stdio.h>
struct emp
{
char name[20];
int age;
};
int main()
{
emp int xx;
int a;
printf("%d\n", &a);
return 0;
}
Answer: Option
Explanation:
There is an error in the line emp int xx;
To overcome this error, remove the int and add the struct at the begining of emp int xx;
#include<stdio.h>
struct emp
{
char name[20];
int age;
};
int main()
{
struct emp xx;
int a;
printf("%d\n", &a);
return 0;
}
Discussion:
30 comments Page 2 of 3.
Mahi said:
8 years ago
The normal declaration of structure is:
Struct emp xx;
Coming to printf statement it gives the address of 'a' in negative because pointer is unsigned integer.
Struct emp xx;
Coming to printf statement it gives the address of 'a' in negative because pointer is unsigned integer.
Sri said:
9 years ago
Why should we place struct?
K.R.Shivraj said:
9 years ago
Yes, we can use & in printf statement refer tutorials point for your better clearance.
Sesi Praveen said:
10 years ago
a is not defined. How can it print the value of a? It is an error, somebody reply.
Kausar Barkat said:
1 decade ago
What about the & sign in printf statement? Isn't that an error?
Dan said:
1 decade ago
We can't write & in printf statement.
Balki said:
1 decade ago
The & symbol here will print the address of the variable 'a' and there is nothing wrong in using it in a printf statement.
Here it has been mentioned just to confuse us.
The real error lies in the declaration of structure.
Here it has been mentioned just to confuse us.
The real error lies in the declaration of structure.
Ashu said:
1 decade ago
& operator we can not used in printf it should be in scanf.
Hashni said:
1 decade ago
& Operator should be used only in scanf() statement.
Sameera said:
1 decade ago
You are correct vasantha deepika.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers