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 6 of 6.
Harsh said:
1 decade ago
@Kavyashree.
You are absolutely correct.
You are absolutely correct.
Pranoy said:
1 decade ago
@KavyaShree@Hann
Dont worry Kavya your assumption is absolutely.
The code what You have written is true.
And, Hann it is not necassary to ask a variable to print the data type, since it takes as null if not assigned
Dont worry Kavya your assumption is absolutely.
The code what You have written is true.
And, Hann it is not necassary to ask a variable to print the data type, since it takes as null if not assigned
Hann said:
1 decade ago
Its like
char str[]="good";
printf("%s",str);
its jst like replacing str with "good"
it becomes printf("%s","good");
output will be:
good
char str[]="good";
printf("%s",str);
its jst like replacing str with "good"
it becomes printf("%s","good");
output will be:
good
(1)
Ranjan said:
1 decade ago
@Kavyashree
your assumption is wrong, as it will ask a variable to print the data type, by the way the code offered from you shows error.
your assumption is wrong, as it will ask a variable to print the data type, by the way the code offered from you shows error.
Kavyashree said:
1 decade ago
Its because
The statement printf(str, "K\n"); is replaced with printf("%s" , "K\n");
// since str = "%s";
So it will print K.
The statement printf(str, "K\n"); is replaced with printf("%s" , "K\n");
// since str = "%s";
So it will print K.
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 "".
Roshan zameer said:
2 decades ago
Str doesnot return.. so the value(k )inside brace isdisplayed..
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers