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

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

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

Mohit said:   10 years ago
Change %s with %c, %x. You will see that str is replace by different output.
(2)

Mitali said:   10 years ago
@Shahin.

How it will give garbage value as an output?

Shahin said:   1 decade ago
@Nithiya.

The output will be garbage value.

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?

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

What will be the output?

Amir Khan said:   1 decade ago
Can anyone explain me this:

If,
int *str="abcd"
Then first character will be 'a' not '"'(Double quotes).

Then, if we initialize as,
str = "%s";
printf(str, "K\n");

Then printf requires "--"(double quotes).

And if we replace str value in printf function, then it will write as,
printf(%s,"K\n");

Got my point everybody? Please reply me.
(2)

Bhavin said:   1 decade ago
What we write in double quotes will get printed simple?

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

please explain this output: hi.

Singh is king said:   1 decade ago
Based on the total var we need to specify scope identifiers.


Post your comments here:

Your comments will be displayed after verification.