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 1 of 3.
Shrutika said:
5 months ago
Why we're taking %d as a format specifier because actually we want the address to get printed So, we must use %p as a format specifier.
Kajal said:
4 years ago
As per my knowledge, We can't use & in printf statement.
Kalyani said:
4 years ago
Could anyone please explain what is emp?
(1)
Divya said:
5 years ago
where is "int a" used? Please explain me.
Vaibhav said:
5 years ago
How can I identify?
That,
emp int xx; is an error can anyone help me?
That,
emp int xx; is an error can anyone help me?
Subhra said:
5 years ago
The printf will print the address of a.
Harsh said:
6 years ago
@Sesi Praveen.
'a' is not initialized. The Compiler will take by the default value for a in print statement. The Main error is in emp int xx statement.
'a' is not initialized. The Compiler will take by the default value for a in print statement. The Main error is in emp int xx statement.
Jaiyant Prasad said:
6 years ago
We can't use & in print.
So option A is also correct.
So option A is also correct.
Vasudev said:
6 years ago
Generally just after declaration of a variable, no memory will be allotted to the variable so, how can it print the address of the variable a?
Karthik said:
6 years ago
The struct emp xx also doesn't work as it gives an error "two or more data types in declaration of xx"
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers