meaning of this code [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
int main()
{
int x = 2, y = 6, z = 6;
x = y == z;
printf("%d", x);
}

== has higher precedence than =, and y==z is 1.
I will end the answer there, because this looks like homework.

http://codepad.org/fp4ZYJX5

The output is:
1
Have a look at this, which explains a similar, yet more complex question and will answer yours as well.

Output is 1
If you want more help we can give you

Related

a complicate example using loop invariant [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
can anyone supply a complicate example using loop invariant example such as sum(int n) is so trivial that it can not show the power of loop invariant. I want a example that is not that obivious, and we can use method like loop invariant to solve it.
The Wikipedia example is quite good:
for (int i = 0; i < n; i++) {
x = y + z;
a[i] = 6 * i + x * x;
}
Two invariant can be moved (y + z and x * x). The advantage of this example is that after LICM has been applied, you can apply other optimizations on the code to have something very easy.
There are plenty on papers/slides/courses about that, you sure can find a satisfying example.

C while loop not executing [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm learning c and I can't figure out the problem with this code:
#include <stdio.h>
int main(){
int i = 0;
while(i > 10){
printf("hello");
i++;
}
getch();
return 0;
}
I don't get any errors and have tried running it on codeblocks and wxdev c++. So is there something I'm doing wrong. Thanks.
You set
i = 0;
and then test
i > 10
which is always false.
You might want
while (i < 10)
instead.
I is not greater than 10 so it doesnt meet the requirement to enter the while loop
while(i > 10){
...but i is 0 so it's false and skips.
You probably meant to instead write;
while(i < 10) {
Reason: i is not greater than 10.

What does the variable stores when it is assigned a printf statement in C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
void main(){
int i;
i=printf("how r u?\n");
i=printf("%d",i);
printf("%d",i);}
The above code gives the result as:
how r u?
91
My question:
How does stores 9 and 1??
From the man page: Upon successful return, these functions return the number of characters printed.... If an output error is encountered, a negative value is returned.
So you are getting 9 and i because printf wrote out 9 and 1 characters respectively.
This is also relevant: Why does printf return a value?

what is the output of this code and how? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Program to understand sizeof operator:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char *mess[]={ //array of pointers
"amol is a good boy",
"robin singh",
"genious boy",
"bitch please"
};
printf("%d",sizeof(mess)); // what does sizeof operator do?
}
Please explain the output of this code.
It is the storage size in bytes of 4 pointers to char.
You have your answer right in your question. It has a size of an array of pointers.
So the size is 4 * size of a pointer. (which is 32 on my system.) Your system might vary.

factorial using recursion+pointers [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
i am learning C programming, i was trying to write a recursive function by using this prototype:
void fact(int *n);
The parameter of this function should be passed by reference. Thanks for your help.
I don't feel to be helpful in giving a complete solution -- this is just to show there is an answer:
void fact(int *n)
{
if (*n > 1)
{
int tmp = *n - 1;
fact(&tmp);
*n *= tmp;
}
}
I would never write a factorial function this way.

Resources