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 1 of 6.
Sajid said:
2 decades ago
Why no add the explanation.
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..
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.
François said:
1 decade ago
This is what I get when trying to compile with gcc or cc
/tmp/cchEohai.o: In function `main':
test.c:(.text+0x32): undefined reference to `strupr'
collect2: ld returned 1 exit status
Do I need to add a particular standard header here?
/tmp/cchEohai.o: In function `main':
test.c:(.text+0x32): undefined reference to `strupr'
collect2: ld returned 1 exit status
Do I need to add a particular standard header here?
Srinag boda said:
1 decade ago
@fans: did u include string.h?
Punitha said:
1 decade ago
@ sringa boda.
You are brilliant.
You are brilliant.
Midhun said:
1 decade ago
*n denotes Dravid
age=23
e1=Dravid,23
e2=e1 that means e2=Dravid,23
strupr(e2.n) means Dravid but using strupr used to convert Lower letter to upper letter so Dravid
again says that e2=e1
it is printing e1.n means DRAVID So op is DRAVID
age=23
e1=Dravid,23
e2=e1 that means e2=Dravid,23
strupr(e2.n) means Dravid but using strupr used to convert Lower letter to upper letter so Dravid
again says that e2=e1
it is printing e1.n means DRAVID So op is DRAVID
Ravi chaitanya said:
1 decade ago
strupr-> converts the string into upper case
strlwr-> converts the string to lower case
C strings manipulation functions
strlwr-> converts the string to lower case
C strings manipulation functions
N n said:
1 decade ago
strupr and strlwr are not part of the ANSI C standard. This question is pointless if your std C library doesn't have the functions.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers