August 27, 2019

Srikaanth

OpenText C Language Interview Questions Answers

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;
OpenText Most Frequently Asked C Language Interview Questions Answers
OpenText Most Frequently Asked C Language Interview Questions Answers

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();
}


Mention The Characteristics Of Arrays In C?

An array holds elements that have the same data type.
Array elements are stored in subsequent memory locations.
Two-dimensional array elements are stored row by row in subsequent memory locations.
Array name represents the address of the starting element.
Array size should be mentioned in the declaration. Array size must be a constant expression and not a variable.
Differentiate Between A Linker And Linkage?

A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

What Are The Advantages Of Auto Variables?

The same auto variable name can be used in different blocks.
There is no side effect by changing the values in the blocks.
The memory is economically used.
Auto variables have inherent protection because of local scope.

What Is Storage Class And What Are Storage Variable?

A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage. There are five types of storage classes.

auto.
static.
extern.
register.
typedef.

Which Expression Always Return True? Which Always Return False?

expression if (a=0) always return false.
expression if (a=1) always return true.

Is It Possible To Execute Code Even After The Program Exits The Main () Function?

The standard C library provides a function named at exit () that can be used to perform “cleanup” operations when your program terminates. You can set up a set of functions you want to perform automatically when your program exits by passing function pointers to the at exit() function.

Why Should I Prototype A Function?

A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place.

How Do You Print An Address?

The safest way is to use printf () (or fprintf() or sprintf()) with the %P specification. That prints a void pointer (void*). Different compilers might print a pointer with different formats. Your compiler will pick a format that’s right for your environment.

If you have some other kind of pointer (not a void*) and you want to be very safe, cast the pointer to a void*

printf (“%Pn”, (void*) buffer);

Can Math Operations Be Performed On A Void Pointer?

No. Pointer addition and subtraction are based on advancing the pointer by a number of elements. By definition, if you have a void pointer, you don’t know what it’s pointing to, so you don’t know the size of what it’s pointing to. If you want pointer arithmetic to work on raw addresses, use character pointers.

How Can You Determine The Size Of An Allocated Portion Of Memory?

You can’t, really free() can , but there’s no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the compiler.

Subscribe to get more Posts :