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;
}
Error: Invalid structure assignment
DRAVID
Dravid
No output
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
60 comments Page 3 of 6.

Mohamed mekawy said:   1 decade ago
#include<stdio.h>

int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
toupper(e2.n);
printf("%s\n", e1.n);
return 0;
}

The output is "Dravid".

Pradeep shukla said:   10 years ago
Error in GCC compiler ----> undefined reference to 'strupr'.

Raju said:   9 years ago
My GCC compiler gets closed after running this program. Why its happens, anyone helps me.

Robert said:   9 years ago
If you do the above operations in gcc:

*If you assign e2 = e1, e2 will COPY the contents of the structure e1, but e2 will exist independently of e1.
* Whatever changes you will do to either e2 or e1 after that doesn`t impact both. So, if you change variable age in e1 won`t affect the variable age in e2.
* There is no such strupr in string.h.

Ramya said:   9 years ago
@Mohamed Mekawy.

Why there is no effect on 'toupper', why it simply prints 'Dravid' and not printing in uppercase?

Vrushali Vijay Bhoite said:   6 years ago
Thanks @Priyanka.

Mohd Saquib said:   8 years ago
As on compiling on GCC, no output. I got a Runtime error. Why? Please tell me.

Varsha Kurpad said:   8 years ago
Answer will not b DRAVID. Because both e1 and e2 have different tables. How come the changes on e2 affects e1? Can anyone tel me please.

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.

Deepak said:   7 years ago
I have one doubt here, using *n so in the printf statement we need write a1->n, but here writing a1.


Post your comments here:

Your comments will be displayed after verification.