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;
}
Error
No output
K
%s
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
58 comments Page 4 of 6.

Abu zaid said:   1 decade ago
%s is the format specifier type of string.

We can declare it anywhere in the local scope.
(2)

Nirlepsingh said:   2 decades ago
how str="%s" is true
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?

Nagraj said:   1 decade ago
@Alim

printf("%c\n", str);
in this statement why it prints "$"

Mohit said:   1 decade 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.

Manjeet said:   1 decade 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".


Post your comments here:

Your comments will be displayed after verification.