October 16, 2018

Srikaanth

WNS Global Most Frequently Asked C Language Interview Questions Answers

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.
WNS Global Most Frequently Asked C Language Interview Questions Answers
WNS Global Most Frequently Asked C Language Interview Questions Answers

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 :