October 28, 2018

Srikaanth

Synechron Most Frequently Asked C Language Interview Questions Answers

What is the advantage of an array over individual variables?

When storing multiple related data, it is a good idea to use arrays. This is because arrays are named using only 1 word followed by an element number. For example: to store the 10 test results of 1 student, one can use 10 different variable names (grade1, grade2, grade3… grade10). With arrays, only 1 name is used, the rest are accessible through the index name (grade[0], grade[1], grade[2]… grade[9]).

Write a loop statement that will show the following output:

1
12
123
1234
12345

Answer:

for (a=1; a<=5; i++) {
for (b=1; b<=a; b++)
printf("%d",b);
printf("\n");
}
Synechron Most Frequently Asked C Language Interview Questions Answers
Synechron Most Frequently Asked C Language Interview Questions Answers

What is wrong in this statement?  scanf(“%d”,whatnumber);

An ampersand & symbol must be placed before the variable name whatnumber. Placing & means whatever integer value is entered by the user is stored at the “address” of the variable name. This is a common mistake for programmers, often leading to logical errors.

How do you generate random numbers in C?

Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

The most probable reason behind this error is that the header file for that function was not indicated at the top of the program. Header files contain the definition and prototype for functions and commands used in a C program. In the case of “tolower()”, the code “#include <ctype.h>” must be present at the beginning of the program.

What are comments and how do you insert it in a C program?

Comments are a great way to put some remarks or description in a program. It can serves as a reminder on what the program is all about, or a description on why a certain code or function was placed there in the first place. Comments begin with /* and ended by */ characters. Comments can be a single line, or can even span several lines. It can be placed anywhere in the program.

What is debugging?

Debugging is the process of identifying errors within a program. During program compilation, errors that are found will stop the program from executing completely. At this state, the programmer would look into the possible portions where the error occurred. Debugging ensures the removal of errors, and plays an important role in ensuring that the expected program output is met.

What are binary trees?

Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.

Not all reserved words are written in lowercase. TRUE or FALSE?

FALSE. All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.

What is the difference between the expression “++a”  and “a++”?

In the first expression, the increment would happen first on variable a, and the resulting value will be the one to be used. This is also known as a prefix increment. In the second expression, the current value of variable a would the one to be used in an operation, before the value of a itself is incremented. This is also known as postfix increment.

What would happen to X in this expression: X += 15;  (assuming the value of X is 5)

X +=15 is a short method of writing X = X + 15, so if the initial value of X is 5, then 5 + 15 = 20.

In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

FALSE. C language is a case sensitive language. Therefore, NAME, name and Name are three uniquely different variables.

What is an endless loop?

An endless loop can mean two things. One is that it was designed to loop continuously until the condition within the loop is met, after which a break function would cause the program to step out of the loop. Another idea of an endless loop is when an incorrect loop condition was written, causing the loop to run erroneously forever. Endless loops are oftentimes referred to as infinite loops.

What is a program flowchart and how does it help in writing a program?

A flowchart provides a visual representation of the step by step procedure towards solving a given problem. Flowcharts are made of symbols, with each symbol in the form of different shapes. Each shape may represent a particular entity within the entire program structure, such as a process, a condition, or even an input/output phase.

What is wrong with this program statement? void = 10;

The word void is a reserved word in C language. You cannot use reserved words as a user-defined variable.

Is this program statement valid? INT = 10.50;

Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a reserved word and must not be used for other purposes. However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.


Write a program to print factorial of given number without using recursion?

#include<stdio.h>
#include<conio.h>
void main(){
  int i,fact=1,number;
  clrscr();
  printf("Enter a number: ");
  scanf("%d",&number);

  for(i=1;i<=number;i++){
      fact=fact*i;
  }
  printf("Factorial of %d is: %d",number,fact);
  getch();
}

Write a program to print factorial of given number using recursion?

#include<stdio.h>
#include<conio.h>
 long factorial(int n)    // function to calculate the factorial of a given number.
{
  if (n == 0)
    return 1;
else
return(n * factorial(n-1));    //calling the function recursively.
}
 void main()
{
  int number;    //declaration of variables.
  long fact;
 clrscr();
  printf("Enter a number: ");
scanf("%d", &number); 
 fact = factorial(number);    //calling a function.
printf("Factorial of %d is %ld\n", number, fact);
 getch();   //It reads a character from the keyword.
}

What are actual arguments?

When you create and use functions that need to perform an action on some given values, you need to pass these given values to that function. The values that are being passed into the called function are referred to as actual arguments.

Subscribe to get more Posts :