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 3 of 6.

Kartik said:   1 decade ago
Why is the need for this kind of format: printf ("%s", "hello").
If we can simply print using: printf ("hello") ;.
TAKE A MOMENT Please!

Assasin said:   1 decade ago
#include<stdio.h>
#include<conio.h>
int main()
{
printf("hi","bye");
}

please explain this output: hi.

Nithiya said:   1 decade ago
int main()
{
int *str;
str = "%d";
printf(str, "5\n");
return 0;
}

What will be the output?

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.

Omkar said:   1 decade ago
@Ravi.

Your code is working, its working because printf function needs one fixed argument and n variable arguments.

Sree said:   1 decade ago
Hai kavyashree.

Printf ("%s", "k\n") ; why %s is not shown as output which in double quotes. Only k as output.

Prakash said:   5 months ago
There is no format specifier in print statement. So it doesn't print the structure value it only prints the K.

Shahin said:   1 decade ago
So, can we assign a format specifier to the variable ? If so, the above solution will be correct explain me?

Sandeep(MCA) said:   1 decade ago
It will print k because we don't add the %c with str. So it will print only massage which is in "".

Abu zaid said:   10 years ago
%s is the format specifier type of string.

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


Post your comments here:

Your comments will be displayed after verification.