Here are some questions related to Style of writing C programs:
Question-1: Why i++ executes faster than i + 1 ?
Answer-1: The expression i++ requires a single machine instruction such as INR to carry out the increment operation whereas, i + 1 requires more instructions to carry out this operation.
Question-2: Is writing if(! strcmp(s1, s2) ) a good style ?
Answer-2: No, this is not a good style because if(! strcmp(s1, s2) ) invokes undefined behavior, so it might be confusing .
Question-3: What is the best style for code layout in C ?
Answer-3: There are many systems of indentation advocated, but all of them have the same basic flaw . They will mislead the reader when the actual code logic does not follow the indentation . It is better to avoid indentation entirely, so the reader will not be misled .
Question-4: Is goto a good thing or a bad thing ?
Answer-4: We should avoid using goto statement, Use it only when necessary .
Question-5: Why pre-increment operator is faster than post-increment operator ?
Answer-5: Evaluation of any expression is from left to right . Preincrement operator is faster than Postincrement operator because it does not save the current value for next instruction, whereas Postincrement needs to save the current value to be incremented after execution of the current instruction.
Question-6: What is the output of printf(“%d”) ?
Answer-6: printf(“%d”, i) means that the compiler will print the value of i, since there is nothing after %d so the compiler will show garbage value in output window .
- Common Memory/Pointer Related bug in C Programs
- C++ programming and STL facts
- Interesting Facts about C++
- Writing first C++ program : Hello World example
- Writing OS Independent Code in C/C++
- Interesting Facts in C Programming
- Interesting facts about C Language
- C++ bitset interesting facts
- Interesting Facts about Macros and Preprocessors in C
- Interesting facts about switch statement in C
- Some Interesting facts about default arguments in C++
- How to convert C style strings to std::string and vice versa?
- Writing C/C++ code efficiently in Competitive programming
- Interesting facts about data-types and modifiers in C/C++
- Some interesting facts about static member functions in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.