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.
#include<stdio.h>
int main()
{
for(;NULL;)
printf("STACK");
return 0;
}
output: STACK
I know NULL have ascii value 0 and it's false, but when i run on turbo c, this program give output "STACK", how it is possible.
"STACK" is never outputted. This is because the conditional part of the for statement is always false (assuming NULL is #defined as (void *)0.
The turbo c compiler is ancient ( 20 years old). The behaviour you are seeing is a bug. The 16 bit application isn't running correctly on your OS ( Win7 ?).
As a workaround you can assign the NULL value to a variable and use that in the condition of the for loop, or even better switch to a newer compiler. Like wxdev-cpp
Related
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.
In C, why does the following result in x[1] being 2?
int a = 2, x;
...
printf("x[1] = ", &x[1])
It doesn't. It results in undefined behaviour where anything can happen. You cannot access elements beyond the end of an array in a defined manner.
What's most likely happening is that a is just "above" x on the stack, which results in x[1] having the same address as a, but it's by no means guaranteed.
This is, of course, assuming that your printf is a typo. As it stands, it doesn't even compile. I'm assuming it's a typo since the question title just asks about the value of x[1] rather than the output.
To get it to work, you'd have to use something like:
printf ("x[1] = %d\n", (&x)[1]);
which also prints 2 on my system, but may do something totally different elsewhere.
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.
int a = 8;
if (a==8)
printf("x");
else
printf("y");
Though a is equal to 8, it outputs y.
The code above always prints x. If your code prints something else, then you omitted vital information in your question.
To find out what that might be, try this:
Insert #undef a before the int a = 8; to make sure there isn't a C preprocessor macro that messes with the code.
Swap the condition to see if a is really what you expect:
if( 8 == a )
This little trick also prevents you from the accidental assignment bug (if( a = 8 ))
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.
map[0][4]='\0';
city1[0][4]='\0';
strcpy(map[0],city1[0]);
map[0][0]='z';
printf("%s",map[0]);
printf("%s",city1[0]);
printf("%d \n",strcmp(map[0],city1[0]));
The output of this function is zail
nail
12
Why it is so? What I did not understand about strcmp? Why 12 and not any other number?
To answer your question,
strcmp("zail", "nail")
is evaluating to 12 because it's subtracting the 'n' in "nail" from the 'z' in "zail", and 'z' - 'n' = 12.
You're getting random junk because you're not initializing your arrays properly.
Instead of
map[0][4]='\0';
city1[0][4]='\0';
Try
memset(map[0], '\0', sizeof(map[0]));
memset(city1[0], '\0', sizeof(city1[0]));
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 11 years ago.
I do not know how to use "C", but have a working C program that I need to print a
program variable to determine what the program is doing. Can you tell me the easiest
way to do this
Jack
to print on stdout use printf function from stdio.h
To watch the values of a particular variable in Turbo c (windows)
Window-> watch -> enter your variable name. Then Press F7.
You can able to keep track the value of the variable.
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.
void main()
{
char c='0';
printf("%d %d",sizeof(c),sizeof('0'));
}
In C, size of char literal is equal to sizeof(int). So sizeof('0') gives the value of sizeof(int) on your implementation.
Also sizeof(char) is always 1 as mandated by the Standard.
The output will be 1 4. The type of the '0' literal is int, which on most systems has a size of 4. The C standard requires that sizeof(char) is 1.
If you get anything less than 4, get in your time machine, and dial in +25 years.