C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Point Out Errors (Q.No. 2)
2.
Point out the error in the program?
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
Discussion:
23 comments Page 2 of 3.
Ivon said:
10 years ago
But why I use CodeBlock (GCC compiler) to get it compiled and each scan runs smoothly, just getting wrong value, but it just got value for each place!
Khushi said:
1 decade ago
No its not the case.
It will take input but the values that will get stored will be unexpected and it may lead to segmentation fault as well.
It will take input but the values that will get stored will be unexpected and it may lead to segmentation fault as well.
Shoana Carvalho said:
1 decade ago
What I guess is segmentation fault occurs only when there is buffer overflow comes into existence because of too many function calls!
Afzal said:
9 years ago
@Nitesh Khatri. I understood your explanation.
But, is Shivam's explanation is right?
Does it depend on the Type of data ?
But, is Shivam's explanation is right?
Does it depend on the Type of data ?
Prahlad said:
9 years ago
When I'm compiling in ubuntu I'm just getting a warning not an even error and how can the answer be error?
Please help me.
Please help me.
Sowmiya said:
9 years ago
The 'i' is an integer type. So %d should be used and 'ch' is a character type so %c or %s should be used.
Rup said:
1 decade ago
'i' is an integer type so %d should be used and 'ch' is a character type so %c or %s should be used.
Dhruv gupta said:
7 years ago
But in {B} option printf give output in ASCII value.
So, I think option A is correct.
So, I think option A is correct.
(2)
Shivi said:
1 decade ago
Because %d is a format specifier of int type but ch is a char data type.
Shiv Bhajan said:
1 decade ago
Why it will not get input for the second scanf () ? please Explain it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers