As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
if (++bufCnt >= smenu->bufSize) //line1
if (bufCnt++ >= smenu->bufSize) //line2
In line1 bfrCnt is first incremented and then compared. In line2 it is first compared and then incremented. Is this correct?
Correct.
In both case you increase bufCnt.
But without else if you increase bufCnt two times.
Yes,
In line1 bfrCnt is first incremented and then compared.
In line2 it is first compared and then incremented.
Your question is not having the quality when it is compared to the other questions in this site. That is why you are getting down votes.
So when ever you are posting a question, make sure it is having enough standard.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I have a very short (and pretty much noob) question. I have a function that includes:
void function(int x)
{
x = 3;
if (x == 4)
printf("HI!");
x = 4;
}
Will the word HI! be printed? In other words, is a C program read sequentially or not?
Thanks a lot!
No, the code compiles to a sequence of instructions which happen sequentially one after the other. The comparison to 4 will always before the assignment x = 4. So it will be false.
This type of order is guaranteed when you are dealing with a single thread. When you have multiple threads you can get strange results and race-conditions unless you are careful.
It will not be printed. The line above is what matters of course.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
As an aside: Such a standard typedef would have help reduce the number of reserved words in C/C++, and relegated void to a simple type declaration, e.g. in <stddef.h>. (c.f. SRB in AB33/Mar 1972 - PDF=7kB)
That's pretty speculative. But one good reason is because void is not an empty value; it's the absence of a value. For instance, a function with a signature of int f(void) takes zero arguments, not one.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Before C99 programmers were obliged to define all arrays with fixed sizes that were known at compile time. How did people manage to create and access structures that behaved like arrays but whose sizes were not known until runtime?
With the use of malloc(3) and free(3) to do dynamic memory management. It's still done today.
void f(int n)
{
int *nInts = malloc(n * sizeof(int));
/* do stuff with 'nInts' */
free(nInts);
}
I think you are referring to this.
As said there, it's not really sure if it's legal or portable. That said I have seen code like this but never written it myself.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
The C language requires that all variables used in the program should be declared before any other statements.
Why was this of significance? Was it for readability? If it was for readability, then why don't other languages follow the same rule?
I personally prefer declaring all my variables at the very start.
Moderators: Please delete if this is off-topic or already been asked. I was just keen to know improve my knowledge. Thanks.
Like other people said in comments now it's not mandatory anymore. Anyway it wasn't for readability. C is a very old language and one of its peculiar features is that a C file can be compiled with just one parsing. I think that the earliest version of the language made the choice to declare variable at the beginning for simplify the parsing
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Does anyone know how to write a brute force program where if, say, the lenght is 4, in the beginning, the string would be a\0\0\0, b\0\0\0,..., ab\0\0 and so on, ie keeping its NULLs.
My question is for a password cracking homework.
Thanks
Here's an algorithm:
memset it all to null.
Increment the first character.
Repeat step 2 until the first character overflows.
Increment the second character
Go back to step 2 and repeat until the second character overlows.
Increment the third character.
You get the idea...
I leave the implementation up to you. It's your homework.