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:
57 comments Page 5 of 6.

Alim Ul Karim said:   1 decade ago
#include<stdio.h>

int main()
{
char *str;
str = "%s";
printf(str, "K\n");
printf("%s\n", str); // prints "%s"
printf("%c\n", str); // prints the address and converted it to char , which is '$'
printf("%c\n", *str); // prints '%'
return 0;
}

Suchita said:   1 decade ago
Can we assign int type value to char type pointer? Please give example.

Taniya said:   1 decade ago
Thanx kavyashree.

Prateek said:   1 decade ago
Kavyashree is correct

Arpan V Mohokar said:   1 decade ago
Kavyashree is correct

MERIL said:   1 decade ago
@kavyashree

u r correct
if v replace d code like this
#include<stdio.h>

int main()
{
char *str;
int i=2
str = "%d";
printf(str,i);
return 0;
}

THE O/P WILL BE: 2
***So ur explanation is correct

Rajesh Panse said:   1 decade ago
@kavyashree.

You are absolutely right.

Rahul said:   1 decade ago
str will store address of variable if and only if variable is preceded by &
otherwise it will store value of variable.

Nirlepsingh said:   1 decade ago
how str="%s" is true
because str is a pointer which store adress of characters

Lavanya said:   1 decade ago
@Kavyashree.

Your ans is exactly correct.


Post your comments here:

Your comments will be displayed after verification.