November 19, 2018

Srikaanth

Check Point Software Most Frequently Asked C Language Interview Questions Answers

When is a “switch” statement preferable over an “if” statement?

The switch statement is best used when dealing with selections based on a single variable or expression. However, switch statements can only evaluate integer and character data types.

What are global variables and how do you declare them?

Global variables are variables that can be accessed and manipulated anywhere in the program. To make a variable global, place the variable declaration on the upper portion of the program, just after the preprocessor directives section.

What are enumerated types?

Enumerated types allow the programmer to use more meaningful words as values to a variable. Each item in the enumerated type variable is actually associated with a numeric code. For example, one can create an enumerated type variable named DAYS whose values are Monday, Tuesday… Sunday.

What does the function toupper() do?

It is used to convert any letter to its upper case mode. Toupper() function prototype is declared in <ctype.h>. Note that this function will only convert a single character, and not an entire string.
Check Point Software Most Frequently Asked C Language Interview Questions Answers
Check Point Software Most Frequently Asked C Language Interview Questions Answers

Is it possible to have a function as a parameter in another function?

Yes, that is allowed in C programming. You just need to include the entire function prototype into the parameter field of the other function where it is to be used.

What are multidimensional arrays?

Multidimensional arrays are capable of storing data in a two or more dimensional structure. For example, you can use a 2 dimensional array to store the current position of pieces in a chess game, or position of players in a tic-tac-toe program.

Which function in C can be used to append a string to another string?

The strcat function. It takes two parameters, the source string and the string value to be appended to the source string.

What is the difference between functions getch() and getche()?

Both functions will accept a character input value from the user. When using getch(), the key that was pressed will not appear on the screen, and is automatically captured and assigned to a variable. When using getche(), the key that was pressed by the user will appear on the screen, while at the same time being assigned to a variable.

Dothese two program statements perform the same output? 1) scanf(“%c”, &letter);  2) letter=getchar()

Yes, they both do the exact same thing, which is to accept the next key pressed by the user and assign it to variable named letter.

What is the advantage of a random access file?

If the amount of data stored in a file is fairly large, the use of random access will allow you to search through it quicker. If it had been a sequential access file, you would have to go through one record at a time until you reach the target data. A random access file lets you jump directly to the target address where data is located.

In a switch statement, what will happen if a break statement is omitted?

If a break statement was not placed at the end of a particular case portion? It will move on to the next case portion, possibly causing incorrect output.

Describe how arrays can be passed to a user defined function

One thing to note is that you cannot pass the entire array to a function. Instead, you pass to it a pointer that will point to the array first element in memory. To do this, you indicate the name of the array without the brackets.

What are pointers?

Pointers point to specific areas in the memory. Pointers contain the address of a variable, which in turn may contain a value or even an address to another memory.

Can you pass an entire structure to functions?

Yes, it is possible to pass an entire structure to a function in a call by method style. However, some programmers prefer declaring the structure globally, then pass a variable of that structure type to a function. This method helps maintain consistency and uniformity in terms of argument type.

What is gets() function?

The gets() function allows a full line data entry from the user. When the user presses the enter key to end the input, the entire line of characters is stored to a string variable. Note that the enter key is not included in the variable, but instead a null terminator \0 is placed after the last character.

The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.

How do you search data in a data file using random access method?

Use the fseek() function to perform random access input/ouput on a file. After the file was opened by the fopen() function, the fseek would require three parameters to work: a file pointer to the file, the number of bytes to search, and the point of origin in the file.

Are comments included during the compilation stage and placed in the EXE file as well?

No, comments that were encountered by the compiler are disregarded. Comments are mostly for the guidance of the programmer only and do not have any other significant use in the program functionality.

Is there a built-in function in C that can be used for sorting data?

Yes, use the qsort() function. It is also possible to create user defined functions for sorting, such as those based on the balloon sort and bubble sort algorithm.

What are the advantages and disadvantages of a heap?

Storing data on the heap is slower than it would take when using the stack. However, the main advantage of using the heap is its flexibility. That’s because memory in this structure can be allocated and remove in any particular order. Slowness in the heap can be compensated if an algorithm was well designed and implemented.

How do you convert strings to numbers in C?

You can write you own functions to do string to number conversions, or instead use C’s built in functions. You can use atof to convert to a floating point value, atoi to convert to an integer value, and atol to convert to a long integer value.

Create a simple code fragment that will swap the values of two variables num1 and num2.

int temp;

temp = num1;

num1 = num2;

num2 = temp;

Write a program to print Fibonacci series using recursion?

#include<stdio.h> 
#include<conio.h> 
void printFibonacci(int n) // function to calculate the fibonacci series of a given number.

static int n1=0,n2=1,n3;    // declaration of static variables.
    if(n>0){ 
         n3 = n1 + n2; 
         n1 = n2; 
        n2 = n3; 
         printf("%d ",n3); 
         printFibonacci(n-1);    //calling the function recursively.
    } 

void main(){ 
    int n; 
    clrscr(); 
    printf("Enter the number of elements: "); 
    scanf("%d",&n); 
    printf("Fibonacci Series: "); 
    printf("%d %d ",0,1); 
    printFibonacci(n-2);//n-2 because 2 numbers are already printed 
    getch(); 


Write a program to check prime number in C Programming?

#include<stdio.h> 
#include<conio.h> 
void main() 

int n,i,m=0,flag=0;    //declaration of variables.
clrscr();    //It clears the screen.
printf("Enter the number to check prime:"); 
scanf("%d",&n); 
m=n/2; 
for(i=2;i<=m;i++) 

if(n%i==0) 

printf("Number is not prime"); 
flag=1; 
break;    //break keyword used to terminate from the loop.


if(flag==0) 
printf("Number is prime"); 
getch();    //It reads a character from the keyword.
}

Write a program to check palindrome number in C Programming?

#include<stdio.h>
#include<conio.h>
main()
{
int n,r,sum=0,temp;
clrscr();
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf("palindrome number ");
else
printf("not palindrome");
getch();
}

Subscribe to get more Posts :