Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
#include <stdio.h>
int main()
{
int var=0;
for(; var++; printf("%d",var));
printf("%d", var);
}
Please explain to me this C code. How is the output 1?
You might be confused because of the wrong code indentation. Your code is:
for(; var++; printf("%d",var))
;
printf("%d", var);
So you always get the output of the second printf. As var is initialized to 0 and var++ (the for-condition) is always executed, you end up with var==1.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Can I make a float number in a C program always round up
You can use the ceil() function. For example:
#include <stdio.h>
#include <math.h>
int main () {
float val1 = 1.6;
printf ("Round up to %.1lf\n", ceil(val1));
return(0);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
#include <stdio.h>
#define number 0
main()
{
int i;
for (i = 0; i < 5; i++)
{
number++;
}
printf("Number is: %d", number);
}
No, 0 is substitued for number by the preprocessor before the compiler gets to work.
The compiler issues a diagnostic when it sees 0++;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I was trying to explain to my friend something about C coding and he asked me why his code (with "scanf") didn't work.
#include
int main() {
char x=scanf("%c",&x);
printf("%c\n",x);
return 0;
}
and this one yes
#include <stdio.h>
int main()
{
int k;
char x=getchar
printf("%c\n",x);
return 0;
}
When scanf completes, x contains the character that was read. However, that value is immediately overwritten when x is assigned the return value of scanf, which is the number of items successfully matched or EOF in the event of an error.
If you call scanf without assigning the return value to x you should get the expected result.
For example, this should work.
char x;
scanf("%c",&x);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I really don't understands this code:
#include <stdio.h>
int main (int argument c, char *argument v[])
{
return 0;
}
What does this code mean? How does it converts to other formation of coding?
This is (almost) the simplest C/C++ program. (It works for both languages.) It does nothing other than return 0, which signifies successful execution.
It should read
int main(int argc, char **argv)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Following is the code to obtain matrix like 11 12 13 etc... I am not getting desired results since long. Help me with the solution.
#include<stdio.h>
int main() {
int i,j;
for(i=1;i<5;i++){
for(j=1;j<5;j++){
printf("%d %d",i,j);
}
printf("\n");
}
fgetc(stdin);
}
Probably because you have a space between the digits:
printf("%d %d",i,j);
Shouldn't it be:
printf("%d%d ",i,j);
for your desired output?
Shouldn't printf("%d %d",i,j); actually be printf("%d%d ",i,j);?