C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 8)
8.
What will be the output of the program in Turbo C (under DOS)?
#include<stdio.h>
int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
Discussion:
60 comments Page 3 of 6.
Naina said:
1 decade ago
The value of e1 is passed in e2 and then changes are made to the value present in e2 and then we want to print the values of e1 then dravid shld come in lower case then how come output we get in upper case.
Manoj said:
1 decade ago
@Bhanu is correct.
This code will not work.
n is a pointer (not a array) pointing to a constant string. If we declare n as "char n[20]", then only it will work, otherwise it gives segmentation fault.
This code will not work.
n is a pointer (not a array) pointing to a constant string. If we declare n as "char n[20]", then only it will work, otherwise it gives segmentation fault.
Nikki said:
1 decade ago
I think for e2 a new memory will be created and takes the same value as that of e1. So when changes are made in e2 is not going to be reflected in e1. Then the answer should be "@dravid" right.
Aakash said:
1 decade ago
Guys just a simple question.
e1 and e2 both are objects of same structure but they both occupy the different memory spaces. So when we are doing any change in e2, how it can affect e1?
e1 and e2 both are objects of same structure but they both occupy the different memory spaces. So when we are doing any change in e2, how it can affect e1?
Bhanu said:
1 decade ago
I don't think this code works. n is a pointer (not a array) pointing to a constant string. If we should declare n as "char n[20]", otherwise it gives segmentation fault.
Priyanka said:
1 decade ago
Here e1 & e2 point to same obj. Since e2 makes changes in name using strupr function which converts string to upper case the changes gets reflected in e1 & o/p is DRAVID.
Maheshkumar said:
2 decades ago
As the character pointer "n" points to the string "DRAVID" ,n implies the name of the string,with that the string can be accesed ,that's what its prints..
Deepak choudhary said:
1 decade ago
The output will be Dravid not DRAVID.
as the value e2.n has been modified by the strupr() function, which has nothing to do with e1.n .
so the output is option 3. (Dravid)
as the value e2.n has been modified by the strupr() function, which has nothing to do with e1.n .
so the output is option 3. (Dravid)
Noel said:
7 years ago
No, strupr is an undeclared variable with or without string. Here; h causes the program to crash.
Remove strupr and you get the output Dravid - no CAPS just Dravid.
Remove strupr and you get the output Dravid - no CAPS just Dravid.
Venky said:
1 decade ago
@N N is correct.
There is no existence of such functions in standard C.
If we try to check manual page of strupr and strlwr. It shows there is no manual page.
There is no existence of such functions in standard C.
If we try to check manual page of strupr and strlwr. It shows there is no manual page.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers