What will be the output of the following program? #include<stdio.h> static int x[10]; void main() { int a=0; x[a]=a++|a; x[a]=a++&a; x[a]=a++|a; printf("%d %d %d %d",a, x[0],x[1],x[2]); } O/P : 3 1 2 3
Frequently Asked Questions - C
what are different storage class types in C? Ans: Register,Auto,Static,extern
what are different data types in C? Ans:int,char,float,double,long
what are different types specifiers in C? Ans: void,char,int,float,double,long,short, signed, unsigned,struct,union,enum.
what are different types of qualifiers in C?Ans: Const and Volatile
What does static variable mean? Ans: static declaration limits the variable to file or function scope,Even though its existence is through life time of process only the file or function can modify the variable
What is a pointer? Ans : pointer is address to a location pointers can store address of predefined data types or structures (derived data types) or functions.
What is a structure? Ans : Structure is a derived data type which can be group of similar data types or different data types
What are the differences between structures and arrays? Ans :Arrays is a group of similar data types but Structures can be group of different data types
In header files whether functions are declared or defined? Ans : Generally declared.
What are the differences between malloc() and realloc() and calloc()? Ans :malloc allocates required amount of memory where as realloc allocates required amount of memory but with values retained and calloc allocates memory with requested amount of memory and sets all values to zeoros. Prototype : void * malloc (size) void * realloc(old ptr,size) void*calloc(size_t noofelements,size_t size of each element)
What are macros? what are its advantages and disadvantages? Ans:.Macros are processor directive which will be replaced at compile time
the disadvantage with macros is that they just replace the code they are not function calls. similarly the advantage is they can reduce time for replacing the same values.
Difference between pass by reference and pass by value? Ans : Pass by value just passes the value from caller to calling function so the called function cannot modify the values in caller function.But Pass by reference will pass the address to the caller function instead of value if called function requires to modify any value it can directly modify.
What is static identifier? Ans :
Where are the auto variables stored? Ans : Auto variable are stored in stack
Where does global, static, local, register variables, free memory and C Program instructions get stored? Ans : local - stack, free memory - heap,c Program instructions - Text or code segment,register variables - registers,static - bss, global - Data segment refer the following document - segment is C
Difference between arrays and linked list? Ans: Arrays are created at statically but linked list can be crated dynamically. Arrays will be in stack but linked list are heap.
What are enumerations? Ans:In mathematics and theoretical computer science, the broadest and most abstract definition of an enumeration of a set is an exact listing of all of its elements (perhaps with repetition).
Describe about storage allocation and scope of global, extern, static, local and register variables? Ans : global - visible to all files can be used across files by using keyword extern, scope is through out program - location Data segment. static - similar to global variable(only regarding lifetime of the variable) but scope limited to function or file - location BSS .local - scope with in the function located in stack.register - scope with in the function - register.
What are register variables? What are the advantage of using register variables? Ans :If any variable is declared as register is called register variable. Advantage is fast access.
What is the use of typedef? Ans : typedef - The intent is to make it easier for programmers to comprehend the source code
Can we specify variable field width in a scanf() format string? If possible how? Ans : goto wikianswers
Out of fgets() and gets() which function is safe to use and why? Ans : goto wikianswers
Difference between strdup and strcpy? Ans : goto wikianswer
What is recursion? Ans : recursion means calling the same function it self.
Differentiate between a for loop and a while loop? What are it uses? Ans : for loop and while loop are similar but in for loop you can initialize the value which will be done only at entry to for loop and you can do other functions like increment or decrement(we often do) or printing etc.
What are the different storage classes in C? Ans : auto,register,static,extern
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? Ans : p = a, &a[i][j][k][l] is p+i+j+k+l;
What is difference between Structure and Unions? Ans : in case of structure each variables have their own storage location whereas for unions all the variables share a common memory location. In structure all the variables can be handled at a time but for union only a member can be handled at a time.
What the advantages of using Unions? Ans : unions share common memory location
What are the advantages of using pointers in a program? Ans : refer wikianswers
What is the difference between Strings and Arrays? Ans : refer wikianswers
In a header file whether functions are declared or defined? Ans : declared usually.
What is a far pointer? where we use it? Ans : refer wikianswers
How will you declare an array of three function pointers where each function receives two ints and returns a float? Ans : float (*fptr[3])(int,int);
what is a NULL Pointer? Whether it is same as an uninitialized pointer? Ans : pointer with value 0 is called null pointer.It is different from uninitialized pointer
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro? Ans : for questions 31 and 32 refer wikianswers
What does the error 'Null Pointer Assignment' mean and what causes this error? Ans : it is run time error when ever our program tries to access 0th location i.e. write or read form that location.
What is near, far and huge pointers? How many bytes are occupied by them? Ans : refer wikianswers
How would you obtain segment and offset addresses from a far address of a memory location? Ans : refer wikianswers
Are the expressions arr and &arr same for an array of integers? Ans : not same wikianswers
Does mentioning the array name gives the base address in all the contexts? Ans : It will always treat.
Explain one method to process an entire string as one unit? Ans : refer wikianswers
What is the similarity between a Structure, Union and enumeration? Ans : as far as I know they are user defined data types.
Can a Structure contain a Pointer to itself? Ans : yes
How can we check whether the contents of two structure variables are same or not? Ans :
How are Structure passing and returning implemented by the complier? Ans : it is compiler dependent. Some compilers push structures to stack and other will operate with passing address.
How can we read/write Structures from/to data files?
What is the difference between an enumeration and a set of pre-processor # defines? Ans : enumerations will have continuous values if values are not assigned but #defines should have values predefines
what do the 'c' and 'v' in argc and argv stand for? Ans : "argc" stands for "argument count". It is the number of elements in "argv", "argument vector". (While "vector" and "array" mean different things in java, traditionally they are synonyms.) reference
Are the variables argc and argv are local to main? Ans : yes
What is the maximum combined length of command line arguments including the space between adjacent arguments? Ans : will be compiler dependent.
If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function? Ans: refer wikianswers
What are bit fields? What is the use of bit fields in a Structure declaration? Ans : refer wikianswers
To which numbering system can the binary number 1101100100111100 be easily converted to? Ans : Hexa decimal or octal
Which bit wise operator is suitable for checking whether a particular bit is on or off? Ans : bit wise and
Which bit wise operator is suitable for turning off a particular bit in a number? Ans : bit wise and.
Which bit wise operator is suitable for turning on a particular bit in a number? Ans : bit wise or.
which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1? Ans : Left shifting by one for unsigned number for signed left shift by 1 and restore the most significant bit.
Write a program to compare two strings without using the strcmp() function.
Ans :
signed int funs32strcmp(const char * ps8string1, const char * ps8string2)
{
unsigned int u32stringlen1 = 0,u32stringlen2= 0;
if((ps8string1 == NULL) ||(ps8string2 = NULL))
return(-1);
while(*ps8string1 != '')
u32stringlen1 ++;
u32stringlen1 ++;
while(*ps8string2 != '')
u32stringlen2 ++;
u32stringlen2 ++;
if(u32stringlen2 != u32stringlen1)
return(-1);
while(u32stringlen1 != 0)
{
u32stringlen1--;
if( (*(ps8string1+u32stringlen1)) != (*(ps8string2+u32stringlen2)))
return(-1);
}
return(0);
}
Write a program to concatenate two strings.
Ans :
signed int funs32strcat(char * ps8dststr,const char * ps8secstr)
{
char * ps8TmpDstString = ps8dststr;
const char * ps8TmpSrcString = ps8secstr;
if( (ps8dststr == NULL) || (ps8secstr == NULL))
{
return(-1);
}
while((*ps8TmpDstString) != '')
ps8TmpDstString ++;do
{
*ps8TmpDstString = *ps8TmpSrcString;
ps8TmpSrcString ++;
ps8TmpDstString ++;
}while((*ps8TmpSrcString) != '');
}
Write a program to interchange 2 variables without using the third one.
Ans :
int main()
{
int var1,var2;
scanf("%d %d",&var1,&var2);
var1^=var2^=var1^=var2;
return(0);
}
Write programs for String Reversal & Palindrome check
Ans : refer wikianswers and wikianswers
Write a program to find the Factorial of a number
Ans : refer wikianswers
Write a program to generate the Fibinocci Series
Ans : refer wikianswers
Write a program which employs Recursion
Ans : refer wikianswers
Write a program which uses Command Line Arguments
Ans : refer wikianswers
Write a program which uses functions like strcmp(), strcpy()? etc
What are the advantages of using typedef in a program?
Ans : refer wikianswers
How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
Ans : refer wikianswers
How can you increase the size of a dynamically allocated array?
Ans : by using realloc;
How can you increase the size of a statically allocated array?
Ans : refer wikianswers
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
Which function should be used to free the memory allocated by calloc()?
Ans : free(pointer returned by calloc);
How much maximum can you allocate in a single call to malloc()?
Ans :
Can you dynamically allocate arrays in expanded memory?
Ans :
What is object file? How can you access object file?
Ans : object file is a pre-compiled file,but not linked.If you want to access object file you need to access it by using header file to the object file, and at the time of linking you need to provide the object file.
Which header file should you include if you are to develop a function which can accept variable number of arguments?
Ans : stdarg.h
Can you write a function similar to printf()?
Ans : refer wikianswers
How can a called function determine the number of arguments that have been passed to it?
Ans : no such function.
Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
Ans : no
How do you declare the following:
An array of three pointers to chars -> char *(ps8arr[3]);
An array of three char pointers -> char *(ps8arr[3]);
A pointer to array of three chars char * p;
A pointer to function which receives an int pointer and returns a float pointer -> float *(*function)(int *);
A pointer to a function which receives nothing and returns nothing void (*function)();
What do the functions atoi(), itoa() and gcvt() do?
Does there exist any other function which can be used to convert an integer or a float to a string?
How would you use qsort() function to sort an array of structures?
Ans:
//write in ascending order
#include <stdio.h>
#include <stdlib.h>
int compare(const void * var1,const void * var2)
{
if(*(int *)var1 > *(int *)var2)
{
return(1);
}
else{
return(0);
}
}
void main()
{
unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10};
qsort(au32Nos,10,4,compare);printf("%d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]);
}//program to write in descending order
#include <stdio.h>
#include <stdlib.h>
int compare(const void * var1,const void * var2)
{
if(*(int *)var1 > *(int *)var2)
{
return(0);
}
else{
return(1);
}
}
void main()
{
unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10};
qsort(au32Nos,10,4,compare);
printf("%d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]);
}
How would you use qsort() function to sort the name stored in an array of pointers to string?
How would you use bsearch() function to search a name stored in array of pointers to string?
How would you use the functions sin(), pow(), sqrt()?
How would you use the functions memcpy(), memset(), memmove()?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
How would you obtain the current time and difference between two times?
How would you use the functions randomize() and random()?
How would you implement a substr() function that extracts a sub string from a given string?
What is the difference between the functions rand(), random(), srand() and randomize()?
What is the difference between the functions memmove() and memcpy()?
Ans : refer wikianswers
How do you print a string on the printer?
Can you use the function fprintf() to display the output on the screen?
No comments:
Post a Comment
తెలుగులో వ్రాయడానికి http://www.google.com/ime/transliteration/ ఉపయోగించండి.
No comments:
Post a Comment
తెలుగులో వ్రాయడానికి http://www.google.com/ime/transliteration/ ఉపయోగించండి.