C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 6)
6.
Point out the error in the program?
#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
char name[20];
int age;
};
int main()
{
struct emp e = {"Sanjay", 35};
modify(&e);
printf("%s %d", e.name, e.age);
return 0;
}
void modify(struct emp *p)
{
p ->age=p->age+2;
}
Answer: Option
Explanation:
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.
Discussion:
16 comments Page 2 of 2.
Dhiraj said:
1 decade ago
Here because giving typedef it is taking firstly the structure declaration. After then we are declaring above modify function like: void modify(q*p). So we are getting correct o/p.
Raji said:
9 years ago
Output coming as Sanjay 37.
No errors.
No errors.
Shalivahana nandish said:
9 years ago
Yes, op absolutely sanjay 37, in GCC compiler doesn't shows the error, in turbo c it shows the error.
Meena said:
9 years ago
Can we pass the address of structure object? Like done in modify(&e).
Gita said:
8 years ago
Yeah correct output is.
Sanjay 37.
Compiled on devc++.
Sanjay 37.
Compiled on devc++.
(1)
Ketaki said:
7 years ago
Answer is 37, no error occur in this.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers