Which of the following is not equivalent to others? [closed] - c

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
Which of the following is not equivalent to the other two? Please tell me when it isn't output different from the other two.
while (i<10) {...}
for (;i<10:) {...}
do {...} while (i<10);
I'll appreciate it for your answer.

The last one is different from the first two! If i==15, then the first two are not executed at all, while the do {} block gets executed once.

The do-while loop is unlike the others in that it will execute at least one time because the condition check happens after the loop body. The other two structures first check whether i<10, then execute the loop body if true.

Related

C programming - loop [closed]

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 2 years ago.
Improve this question
Hello I am starting to learn programming and I would like to know this if someone could help me out.
If we know how many times will loop be done whats the easiest one to use?
You should use as a rule of thumb.
If know iterations --> for
If unknown iterations --> while
If at least one iteration (but not known) --> repeat

How to read multiple lines in string until specified character in C [closed]

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 6 years ago.
Improve this question
Need to read everything until say *** comes up:
Input:
Hey there
how are
you
***
Output:
Hey there
how are
you
Would have used scanf("%[^***]s) but can't read all lines at once.
Only having basic C knowledge
The way I would do this is read one line at a time (with a funcion such as fgets instead of scanf) and then see if the line that you last read is equal to ***. You can use use strcmp to do that but you can also do it by hand if you are not allowed to use strcmp for some reason.

Interpreting a shellcode [closed]

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
I am calling a shellcode using buffer overflow to spawn a root shell. Can somebody explain what this shellcode exactly does? I have tried different shellcodes to spawn a root shell, but this was the only one which worked for me.
\x31\xdb\x89\xd8\xb0\x17\xcd\x80\x31\xdb
\x89\xd8\xb0\x2e\xcd\x80\x31\xc0\x50\x68
\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89
\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd
\x80
On first glance, the code appears to do setuid(0), then setgid(0), then call sys_execve() on some values (which include ASCII codes for "/bin//sh").
Looks like this is pure "payload" code, since I don't see anything to ensure the code is executed on the first place (buffer overflow, stack smashing, etc.).
(Thanks to #Hans Lub for the disassembler link)

Main function in C [closed]

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
I am not sure how will this program behave?
I ran this code but I am not able to figure out any reasoning behind the way it works
int main()
{
return main();
}
main() is a function by itself. The line return main() calls the function again. So in effect it should run an infinite loop. You wouldn't get any output (you said you ran it. didn't it crash?).
In reality it would be like staring into a mirror with another mirror placed behind you. You would only see endless reflections. . :)

Nested for-loop that is only O(n) [closed]

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
How would I write a function that contains a nested for-loop but is only order(n)? Im not sure if i need to use recursion or not.
If the inner for loop is a constant number of loops rather than a variable number of loops, while the outer loop is a variable number of loops (or vice versa) the time complexity is O(n*C) where C is a constant, which just means O(n) (since big O notation is only concerned with growing factors).

Resources