C Programming - Strings - Discussion
Discussion Forum : Strings - Find Output of Program (Q.No. 35)
35.
What will be the output of the following program in 16 bit platform assuming that 1022 is memory address of the string "Hello1" (in Turbo C under DOS) ?
#include<stdio.h>
int main()
{
printf("%u %s\n", &"Hello1", &"Hello2");
return 0;
}
Answer: Option
Explanation:
In printf("%u %s\n", &"Hello", &"Hello");.
The %u format specifier tells the compiler to print the memory address of the "Hello1".
The %s format specifier tells the compiler to print the string "Hello2".
Hence the output of the program is "1022 Hello2".
Discussion:
18 comments Page 2 of 2.
Xcoder said:
1 decade ago
This depends on string format whether "%d" or "%s" or "%u".
Nikki said:
1 decade ago
Does "Hello2" and &"hello2" give the same result? could somebody help me. Please.
Roger said:
1 decade ago
&"Hello2" should print the address, anyone?
Penny said:
1 decade ago
I think for the above program, the output is some "address value" since format specifier "%u" is used in the printf statements.
Ashu said:
1 decade ago
void main() {
char str[]="hello";
clrscr();
printf("str= %u",str);
printf("\nstr= %u","hello");
getch();
}
Output-
str=65520
str=193
I am not able to understand the output
char str[]="hello";
clrscr();
printf("str= %u",str);
printf("\nstr= %u","hello");
getch();
}
Output-
str=65520
str=193
I am not able to understand the output
Divya said:
1 decade ago
Can anyone explain this code?
Puspita said:
1 decade ago
Can you please explain it for me?
Bluehole said:
1 decade ago
Does formal parameter has an address ?
If no then the question is irrelevant.
If no then the question is irrelevant.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers