Common coding mistakes you should avoid in the exam.

Vishal Chauhan
4 min readSep 17, 2020
Photo by Bermix Studio on Unsplash

As a human, we do many mistakes but when it came to examination, you have only one chance. If you don’t clear the exam then you will always regret that I wish I knew it before. If you are able to avoid the common mistakes in this article, you will be ahead of many students who attempt the same coding MCQs in the examinations.

Here, I will discuss with you some mistakes which people repeatedly make in C language programming MCQs and tick the wrong option.

1. Pre-increment and Post-increment

Pre-increment used to increase the value of a variable by one while decrement used to decrease the value by one. Generally, students got confused about this topic and did wrong in the exam.

  1. Post-increment (x++): In post-increment, firstly value gets assigned, and after it will increase by 1 at the end of the statement.
  2. Pre-increment (++x): In pre-increment, firstly the value incremented by 1 and after it will be assigned.

It will apply for pre-decrement and post decrement also.

Try to solve the below code by yourself.

In line 5, first,(x++) assigned the value 10 and increased by 1 in the buffer memory. After that from the buffer memory (++x) got 11 and due to pre-increment, a will be assigned to 12. So, the value of b will be 10 + 12 i.e. 22.

In line 6, printf() function will evaluate from right to left and after that, it will print from left to right. firstly, we evaluate from right to left. Here, (++x) will be increased by 1 and will be 13. After that, (x++) will be assigned the value 13 and increased by 1, and 14 will be stored in the buffer memory. After that, printf() will print the values from left to right, which are: 22, 13, 14, 14.

2. Problems related to the scope

The scope of a variable refers to the area of the program where the variable can be accessed after declaration.

There are three types of scope in C language.

  1. Global scope: Out of all functions.
  2. Local scope: Inside a function or any block.
  3. Formal scope: In function parameters.

The value of the variable in global scope is by default 0 for integer, float, and double data types, and ‘\0’ for the character data type.

Let’s look at the above code. What should be the value of a?

As we can see, 12 is assigned inside the block, and 10 is assigned globally. So, the value of a will be 7, because the scope of both printf() and a = 7 is the same.

Let’s take another example.

In the above code, what should be the output?

Ans: Program will give an error that p is redeclared as a different kind of symbol because the program will get confused between variable p and function p().

3. Some important points

  1. Static variables initialize only once in the program.
  2. Sizeof(‘A’) function return size of ASCII value of ‘A’, i.e. sizeof(65) = 2 (According to 16 bit compiler).
  3. (float/float) or (float/int) or (int/float) returns float value.
  4. In switch case accept only integer, character, and enumerate value.
  5. You can’t modify the base address of an array, the program will give an error.
  6. When there is a question that is compiler-based, then prefer a turbo c++ compiler which is a 16-bit compiler.
  7. Armstrong number or plus perfect number of order n is: armstrong(abcd..) = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n)………..

example: armstrong(1634) = pow(1,4) + pow(6,4) + pow(3,4) + pow(4,4)

These are some little mistakes I think can be useful. I will come with some more mistakes and tips in the next article.

--

--