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 5 of 6.
Teju said:
1 decade ago
Why the output has printed in uppercase?? why it is not in lowercase?
Mohanty said:
1 decade ago
If means e1 is assigned to e2 so as strupr () is used with e2.
So how does the string in e1 change when it is printed?
So how does the string in e1 change when it is printed?
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.
Venky said:
1 decade ago
Hi friends.
There is no existence of strupr () and strlwr () in standard C. So, even we add the string. H header file it will show erro in gcc compiler. Try to check man strupr. It will definitely shows there is no manual entry.
There is no existence of strupr () and strlwr () in standard C. So, even we add the string. H header file it will show erro in gcc compiler. Try to check man strupr. It will definitely shows there is no manual entry.
Jyoti said:
1 decade ago
Hello,It don't have any connection with string library.
As 2 parameters is passing,So 2nd parameter i.e. 23 which was earlier initialized get displayed.
And e2.age+=3;
means e2.age=e2.age+3;
and
struct emp e2=e1;
means e1 is assigned to e2 So 23+3=26
Hope I have explained clearly.
As 2 parameters is passing,So 2nd parameter i.e. 23 which was earlier initialized get displayed.
And e2.age+=3;
means e2.age=e2.age+3;
and
struct emp e2=e1;
means e1 is assigned to e2 So 23+3=26
Hope I have explained clearly.
Samhitha said:
1 decade ago
Hi I had included string.h its giving as error. So I did as follows:
e2.age+=3;
printf("%d",e2.age); //displaying as 26
printf("%d",e1.age); //displaying as 23
Hut its not the concept of copy-constructor. Can anyone explain clearly ?
e2.age+=3;
printf("%d",e2.age); //displaying as 26
printf("%d",e1.age); //displaying as 23
Hut its not the concept of copy-constructor. Can anyone explain clearly ?
Pal chakraborty said:
1 decade ago
It is an example of side effect of copy constructor.
Suppose
e1.n=100;
e2.n=23;
where 100 is a location where the string Dravid starts.
when we write e2=e1 then
e2.n=100;
e2.age=23;
so when strupr(e2.n) or strupr(100) then it capitalizes the string at location 100.as both e1.n and e2.n acess the location 100 so both capitalizes instead of (e2.n);
Suppose
e1.n=100;
e2.n=23;
where 100 is a location where the string Dravid starts.
when we write e2=e1 then
e2.n=100;
e2.age=23;
so when strupr(e2.n) or strupr(100) then it capitalizes the string at location 100.as both e1.n and e2.n acess the location 100 so both capitalizes instead of (e2.n);
Parimal said:
1 decade ago
Nice explain thanks @priyanka.
Bp123 said:
1 decade ago
@bhanu
it will work all well if u wl write n[20] instead of *n
then it will not change the value of e2.n and wl simply print Dravid but if u wl write *n then this time its the address that would be changed so this time it wl change the value of both e1.n as well as e2.n
it will work all well if u wl write n[20] instead of *n
then it will not change the value of e2.n and wl simply print Dravid but if u wl write *n then this time its the address that would be changed so this time it wl change the value of both e1.n as well as e2.n
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers