C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 7)
7.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}
Discussion:
57 comments Page 4 of 6.
Nirlepsingh said:
1 decade ago
how str="%s" is true
because str is a pointer which store adress of characters
because str is a pointer which store adress of characters
Akshit said:
1 decade ago
How can Kavyashree be correct?
Str = Address of first character of string, isn't it?
Str = Address of first character of string, isn't it?
Nagraj said:
1 decade ago
@Alim
printf("%c\n", str);
in this statement why it prints "$"
printf("%c\n", str);
in this statement why it prints "$"
Mohit said:
10 years ago
Change %s with %c, %x. You will see that str is replace by different output.
(2)
Suchita said:
1 decade ago
Can we assign int type value to char type pointer? Please give example.
Sunny said:
1 decade ago
@akshit
bcoz str is a pointer it stores first address of the string.
bcoz str is a pointer it stores first address of the string.
Manjeet said:
10 years ago
So why this not possible when I replace char data type with int?
(1)
Roshan zameer said:
2 decades ago
Str doesnot return.. so the value(k )inside brace isdisplayed..
Rajat said:
1 decade ago
It shows error in turbo c compiler. "declaration syntax error".
Shradha said:
3 years ago
Your explanation is good for understanding. Thank you @Megha.
(2)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers