Skip to main content

C Programming Interview Questions With Answers - Part III.


15. What Is An Unsigned Integer Constant? What Is The Significance Of Declaring A Constant As Unsigned?

Answer: An integer constant is any number in the range -32768 to +32767, because an integer constant always occupies two bytes in memory and in two bytes we cannot store a number bigger than +32767 or smaller than -32768. Out of the two bytes to store an integer, the highest bit is used to store the sign of the integer.

This bit is 1 if the number is negative and 0 if number is positive. Unsigned integer constant is an integer constant which has the permissible range from 0 to 65536.

Significance of declaring a constant as unsigned almost doubles the size of the largest possible value. This happens because on declaring a constant as unsigned, the sixteenth bit is free and is not used to store the sign of the constant.


16. Differentiate Between Break & Continue Statement?

Answer: Two keywords that are very important to looping are break and continue. The break command will exit the most immediately surrounding loop regardless of what the conditions of the loop are. Break is useful if we want to exit a loop under special circumstances.

Continue is another keyword that controls the flow of loops. If we are executing a loop and hit a continue statement, the loop will stop its current iteration, update itself (in the case of for loops) and begin to execute again from the top.

Essentially, the continue statement is saying "this iteration of the loop is done; let's continue with the loop without executing whatever code comes after me."

The syntax of continue statement is simple continue;


17. Differentiate Between GoTo & Break Statement?

Answer: C support GoTo statement to branch unconditionally from one point to another in the program. The goto keyword is followed by a label, which is basically some identifier placed elsewhere in the program where the control is to be transferred.

During running of a program, the statement like "goto label1;" cause the flow of control to the statement immediately following the label "label1". We can have a forward jump or a backward jump.

#include <stdio.h >
void main()
{
  int attempt, number = 46;
  looping: /* a label */
    printf("Guess a number from 0-100\n");
  scanf("%d", & amp; attempt);
  if (number == attempt) {
    printf("You guessed correctly!\n\n");
  } else {
    printf("Let me ask again...\n\n");
    goto looping; /* Jump to the label*/
  }
  getch();
}

whereas Break is useful if we want to exit a loop under special circumstances.

#include <stdio.h>
void main()
{
  int a;
  printf("Pick a number from 1 to 4:\n");
  scanf("%d", & amp; a);
  switch (a) {
  case 1:
    printf("You chose number 1\n");
    break;
  case 2:
    printf("You chose number 2\n");
    break;
  default:
    printf("That's not 1,2,3 or 4!\n");
  }
  getch();
}


18. What Is The Purpose Of The Do-While Loop In C?

Answer: Do-while loop or post tested loop is the loop used when it is necessary to execute the loop at least once in the execution of the program. The syntax of the do-while loop is:

do
{
loop body
} while (condition);


19. What Is The Difference Between Uses Of  For & While Loops?

Answer: When a user wants to initialize, check condition and increment or decrement the value of a variable in a single statement, and using an iterative loop, then the loop used may be for loop.

When the user wants to initialize, check condition and increment or decrement value not using a single iterative loop, then he/she may use the while loop. Only one condition can be checked using the while loop.


20. What Is The Importance Or Purpose Of Main () Function?

Answer: main() is a special function used by C system to tell the computer where the program
starts.

The main() function in C is the most vital part of a program. The program execution occurs from the main() function. The main() function may contain any number of statements and they are sequentially executed. main() function can in turn call other functions.


21. Which Header File Is Used For Screen Handling Function?

Answer: The header file stdio.h contains definitions of constants, macros and types, along with
function declarations for standard I/O functions.



Check Out Other Questions:

16) What are the differences between a structure and a union?
17) What is meant by union?
18) What are the advantages of unions?
19) How can typedef be used to define a type of structure?
20) What is enumeration constant?


21) What is the purpose of main() function?
22) What are the differences between formal arguments and actual arguments of a function?
23) What is call by value in functions?
24) What is call by reference in functions?
25) What are the differences between getchar() and scanf() functions for reading strings?


...Return To C Questions INDEX.

...Return To C Programming INDEX.


... Return To HR Interview Index

Comments

Popular posts from this blog

Tell Me Something About Yourself - Interview Answers.

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview . That's why this statement is often called the "Positioning Statement". One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly. YOUR ANSWERS CAN BE: 1) I am a person with strong interpersonal skills and have the ability to get along well with people . I enjoy challenges and looking for creative solutions to problems. 2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies apti...

What Is (Are) Your Weakness (Weaknesses)? - Interview Answers

There’s a saying – “However small the thorn maybe it has the ability to pierce.” Never say you are a Workaholic, a Perfectionist, etc. because it sounds negative. Try to convert these negative biased qualities into positive ones. For Example, In   place of Workaholic you can say you are a hard worker and always willing to work for extra hours. In place of Perfectionist , you can say you are detail oriented and like to set high standard for work. “Try to specify your weakness as your strength and also highlight it as a benefit.” Your answers can be: 1) One of my weaknesses as I perceive is occasional compromise on time for quality and perfection. 2) I feel I am not very detail-oriented . I’m a person that wants accomplish as much as possible. I realized this hurts quality and therefore I‘m trying hard to find a balance between quality and quantity. 3) At times even when I need help, I try to solve my own problems instead of asking a co-worker who might know...

What Is (Are) Your Strengths? - Interview Answers

This is a simple and popular interview question. Generally people answer it in two ways. There are people who simply state their strength like “I am Young, Dynamic, Intelligent, Smart and so on…”. Such answer is neither right nor wrong but does not help u in any way also. Secondly there are peoples who state their strengths and explain them how he can use his strength for the job and industry. Do not simply state your strength. Everyone has some strength, all you need is to convert them into benefits. In short, try to advertise yourself by converting your features into strengths. “EVERYONE CLAIM THEY ARE HONEST, HARDWORKING, SMART AND SO ON….. BUT WITH AN EXAMPLE IT IS MUCH MORE BELIEVABLE.” Your answers can be : 1) I am a hard worker and because of this ability I can work for additional hours to accomplish my tasks.I am commitment oriented and hence I always enjoy the trust and confidence of my team mates which enables me to perform my duties very easily. 2) I am a...