C- Questions

  1. What does static variable mean?
  2. What is a pointer?
  3. What is a structure?
  4. What are the differences between structures and arrays?
  5. In header files whether functions are declared or defined?
  6. What are the differences between malloc() and calloc()?
  7. What are macros? what are its advantages and disadvantages?
  8. Difference between pass by reference and pass by value?
  9. What is static identifier?
  10. Where are the auto variables stored?
  11. Where does global, static, local, register variables, free memory and C Program instructions get stored?
  12. Difference between arrays and linked list?
  13. What are enumerations?
  14. Describe about storage allocation and scope of global, extern, static, local and register variables?
  15. What are register variables? What are the advantage of using register variables?
  16. What is the use of typedef?
  17. Can we specify variable field width in a scanf() format string? If possible how?
  18. Out of fgets() and gets() which function is safe to use and why?
  19. Difference between strdup and strcpy?
  20. What is recursion?
  21. Differentiate between a for loop and a while loop? What are it uses?
  22. What are the different storage classes in C?
  23. Write down the equivalent pointer __expression for referring the same element a[i][j][k][l]?
  24. What is difference between Structure and Unions?
  25. What the advantages of using Unions?
  26. What are the advantages of using pointers in a program?
  27. What is the difference between Strings and Arrays?
  28. In a header file whether functions are declared or defined?
  29. What is a far pointer? where we use it?
  30. How will you declare an array of three function pointers where each function receives two ints and returns a float?
  31. what is a NULL Pointer? Whether it is same as an uninitialized pointer?
  32. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
  33. What does the error 'Null Pointer Assignment' mean and what causes this error?
  34. What is near, far and huge pointers? How many bytes are occupied by them?
  35. How would you obtain segment and offset addresses from a far address of a memory location?
  36. Are the expressions arr and &arr same for an array of integers?
  37. Does mentioning the array name gives the base address in all the contexts?
  38. Explain one method to process an entire string as one unit?
  39. What is the similarity between a Structure, Union and enumeration?
  40. Can a Structure contain a Pointer to itself?
  41. How can we check whether the contents of two structure variables are same or not?
  42. How are Structure passing and returning implemented by the complier?
  43. How can we read/write Structures from/to data files?
  44. What is the difference between an enumeration and a set of pre-processor # defines?
  45. what do the 'c' and 'v' in argc and argv stand for?
  46. Are the variables argc and argv are local to main?
  47. What is the maximum combined length of command line arguments including the space between adjacent arguments?
  48. 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?
  49. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?
  50. What are bit fields? What is the use of bit fields in a Structure declaration?
  51. To which numbering system can the binary number 1101100100111100 be easily converted to?
  52. Which bit wise operator is suitable for checking whether a particular bit is on or off?
  53. Which bit wise operator is suitable for turning off a particular bit in a number?
  54. Which bit wise operator is suitable for putting on a particular bit in a number?
  55. Which bit wise operator is suitable for checking whether a particular bit is on or off?
  56. which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
  57. Write a program to compare two strings without using the strcmp() function.
  58. Write a program to concatenate two strings.
  59. Write a program to interchange 2 variables without using the third one.
  60. Write programs for String Reversal & Palindrome check
  61. Write a program to find the Factorial of a number
  62. Write a program to generate the Fibinocci Series
  63. Write a program which employs Recursion
  64. Write a program which uses Command Line Arguments
  65. Write a program which uses functions like strcmp(), strcpy()? etc
  66. What are the advantages of using typedef in a program?
  67. How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
  68. How can you increase the size of a dynamically allocated array?
  69. How can you increase the size of a statically allocated array?
  70. 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?
  71. Which function should be used to free the memory allocated by calloc()?
  72. How much maximum can you allocate in a single call to malloc()?
  73. Can you dynamically allocate arrays in expanded memory?
  74. What is object file? How can you access object file?
  75. Which header file should you include if you are to develop a function which can accept variable number of arguments?
  76. Can you write a function similar to printf()?
  77. How can a called function determine the number of arguments that have been passed to it?
  78. Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
  79. How do you declare the following:

o An array of three pointers to chars

o An array of three char pointers

o A pointer to array of three chars

o A pointer to function which receives an int pointer and returns a float pointer

o A pointer to a function which receives nothing and returns nothing

  1. What do the functions atoi(), itoa() and gcvt() do?
  2. Does there exist any other function which can be used to convert an integer or a float to a string?
  3. How would you use qsort() function to sort an array of structures?
  4. How would you use qsort() function to sort the name stored in an array of pointers to string?
  5. How would you use bsearch() function to search a name stored in array of pointers to string?
  6. How would you use the functions sin(), pow(), sqrt()?
  7. How would you use the functions memcpy(), memset(), memmove()?
  8. How would you use the functions fseek(), freed(), fwrite() and ftell()?
  9. How would you obtain the current time and difference between two times?
  10. How would you use the functions randomize() and random()?
  11. How would you implement a substr() function that extracts a sub string from a given string?
  12. What is the difference between the functions rand(), random(), srand() and randomize()?
  13. What is the difference between the functions memmove() and memcpy()?
  14. How do you print a string on the printer?
  15. Can you use the function fprintf() to display the output on the screen?

The Basic sections of ‘C’ are explained taking an example::

/* A program to calculate average of 5 nos given by the user */

/*----------Defining of Constants and Inclusion Of Header Files------*/

#include

#define M 10

/*------------Start Of The Main Program---------------------------------*/

main()

{

/*----------------Declaration of Variables----------------------*/

int i;

int sum ;

/*-----------------Initialization of Values----------------*/

sum=avg=0;

/*---------------Interaction With User and Receiving Required Data----*/

printf(“Please Enter The Values::”\n”);

for (i=0; i<=M; i++)

{

scanf(“%d”, &n);

sum=sum+n;

}

/*---------------Display Of Final Result with The Computation-----------*/

printf(“The Sum of All The Nos is: %d \n

The Average of All The 10 Nos is: %d\n”, sum, sum/10);

}

2) The various data types supported in C are basically divided into 4 types: primary or fundamental, user-defined, derived and empty data set.

The Primary Data Type are mainly divided into 3 types which are sub-divided into many types like:

1) INTEGER (int): different types of integers are:

int, unsigned int, short int, unsigned short int, long int, and unsigned long int

2) Character (char): different types of characters are:

signed char, unsigned char

3) Floating Point (float): different types of floats are:

float, double, long double

An Example Program to Display Various Primary Data Types::

main()

{

int a; /*------int range : -32,768 to 32,767-------*/

short int c; /*------short int range : -127 to 128-------*/

long int d; /*------long int range : -2,147,483,648 to 2,147,483,647-------*/

float e; /*------float range : -3.4E-38 to 3.4E+38-------*/

double f; /*------double range : -1.7E-308 to 1.7E+308 -------*/

char g; /*------int range : -127 to 128-------*/

a=30007;

c=120;

d=89654785;

e=954651.6216549;

f=1.6E;

g=’M’;

printf (“a=%d\n c=%d \n d=%d \n e=%f \n f=%f \n g=%c\n”, a, b, c, d ,e ,f ,g);

RESULT:

a=30007

c=120

d=89654785

e=954651.6216549

f=1.6E

g=M

C Objective Questions

No commas or blanks are allowed within an integer or a real constant. True False A
'void' is a datatype. True False A
'emp name' is a valid variable name. True False B
'unsigned' is a valid variable name. True False B
Operation between an integer and float always yields a float result. True False A
/* The C language.
/* is a procedural language .*/*/
The above statement is valid.
True False B
The default initial value of automatic storage class is 0. True False B
= and = = have the same operation. True False B
Character data types cannot be declared as unsigned. True False B
&& and & operators have the same meaning. True False B
Right shifting an operand 1bit is equivalent to multiplying it by 2.
True False B
The same variable names of automatic type can be used in different functions without any conflict. True False A
printf("%d", sizeof('2')); will print 2. True False B
The expression "b = 3 ^ 2;" will evaluate b = 9. True False B
The expression "int i = j = k = 0;" is invalid. True False A
printf() is not a library function. True False B
The expression (i + j)++ is illegal. True False A
The expression 'int j = 6 + 3 % -9;' evaluates to -1. True False B
p++ executes faster than p + 1. True False A
static variable will not always have assigned value. True False A
Variables declared as register storage type gets stored in CPU registers. True False A
Single operations involving entire arrays are permitted in C. True False A
The main() function can be called from any other function. True False A
The main() function can call itself recursively. True False A
The statement "for (i = 0, j = 2; j <= 10; j++)" is a valid statement in 'C'. True False A
When a user defined function is defined in program, then it has to be called at least once from the main(). True False B
Left shift operator rotates the bits on the left and places them to the right. True False B
A recursive function calls itself again and again. True False A
Only one break can be used in one loop. True False B
Every if statement can be converted into an equivalent switch statement. True False B
Nested macros are allowed. True False B
Expression 4**3 evaluates to 64. True False B
All macro substitutions in a program are done before compilation of the program. True False A
'# define PI = 8;' is the correct declaration of macros. True False B
An array declared as A[100][100] can hold a maximum of 100 elements. True False B
The array 'char name[10] can consist of a maximum of 9 characters. True False A
It is necessary to initialize the array at the time of declaration. True False B
the value *(&i) is same as printing the value of address of i. True False B
A pointer is an indication of the variable to be accessed next. True False B
The contents of a file opened in 'r+' mode cannot be changed. True False B
Union is used to hold different data at different time. True False A
All elements of a structure are allocated contiguous memory locations. True False A
enum helps to create user defined datatype. True False A
The value of an enumerated datatype can be read using scanf() function. True False B
Structures within structures cannot be created. True False B
gets() and puts() are unformatted I/O functions. True False A
The identifier argv[] is a pointer to an array of strings. True False B
fprintf()function can be used to write into console. True False B
fopen() function returns a pointer to the open file. True False A
Which of the following language is predecessor to C Programming Language?



A B BCPL
C++
B
C programming language was developed by



Dennis Ritchie Ken Thompson Bill Gates Peter Norton
A
C is a ___ language




High Level and Procedural Low Level and OOPS Middle Level and Procedural Machine Level and OOPS A
Which escape character can be used to beep from speaker in C?



\a \b \m \n A
Which of the following is invalid?


'' " " 'a' 'abc'
D
A declaration float a, b; occupies ___ of memory




1 byte 4 bytes 8 bytes 16 bytes C
The printf() function retunes which value when an error occurs?



Positive value Zero Negative value None of these C
Identify the wrong statement




putchar(65) putchar('x') putchar("x") putchar('\n') C
Which header file is essential for using strcmp() function?




string.h strings.h text.h strcmp.h A
Which among the following is a unconditional control structure


do-while if-else goto for
C
continue statement is used




to go to the next iteration in a loop come out of a loop exit and return to the main function restarts iterations from beginning of loop D
Which of the following is an example of compounded assignment statement?




a = 5 a += 5 a = b = c a = b C
In the expression - 'x + y + 3z =20'




'x + y' is a keyword 3 and 20 are constants 3z is a constant y is a variable and z is a constant B
The output of the following code is:
void main()
{
int z, a = 5, b = 3;
z = a * 2 + 26 % 3;
printf("%d", z);
}




10 0 12 None of the above C
Which options shows the correct hierarchy of arithmetic operators




**, * or /, + or - **, *, /, +, -
**, /, *, +,-
/ or *, - or + D
The output of the following code is:
void main()
{
float a;
int x = 10, y = 3;
a = x / y;
printf("%f", a);
}




3.999999 Error 3 3.000000 D
The output of the following code is:
void main()
{
char a = 'B';
switch (a)
{
case 'A' : printf("a");
case 'B' : printf("b");
default : printf("c");
}




B b bca bc D
The output of the following code is:
void main()
{
int a = 20;
printf("%d\t%d\n", ++a, a);
}





21 21 20 21 21 20 20 20 C
How many times the following loop will execute?
for (a = 0; a < 4; a++)
printf("hello\n");



3 4 5 infinite B
The output of the following code is:
void main()
{
int a;
int &b = a;
a=100;

printf("b=%d\ta=%d\n", b,a);
}




b=100 a=100 b=100 a=0 b=0 a=100 Error D

The output of the following code is:
void main()
{
int a = 0;
while (a<=50)
for(;;)
if(++a % 50==0)
break;
printf("a = %d", a);
}


a = 100 a = 50 compilation error

runtime error A
The output of the following code is:
int f(int a, int b);
void main()
{
int a = 12, b=154;
printf("%d", f(a, b));
}

int f(int a, int b)
{
if (a if(b==0) return(a);
return (f(b, a % b));
}




2 1 Compilation error Runtime error A
The output of the following code is:
void main()
{
int a = 1, b=2;
int *ip;
ip=&a;
b=*ip;
printf("%d", b);
}





2 1 100 0 B
The output of the following code is:
void main()
{
static int a = 1, b, c;
if (a>=2)
b=2;
c=3;
printf("%d\t%d", b,c);
}




2 3 0 3 0 0 2 0 B
The output of the following code is:
#define sqr(x= x*x)
main()
{
int a = 10, b = 5;
printf("%d, %d", sqr(a+b),sqr(++a));
}




77, 121 225, 121 77, 144 Compilation error D
struct stud
{
int roll;
char name[20];
float marks;
} *p;

What will be the byte size of p?



24 2 26
None B
The output of the following code is:
main()
{
unsigned int a = 10;
while (a>=10)
{
int a;
a-- ;
}
printf("%i", a);
}




Infinite loop 9 0 None A
The output of the following code is:
main()
{
xyz:
goto abc;
printf("Hello");
abc:
printf("World");
goto xyz;
}





Infinite loop Hello World World Hello Compilation error A
The output of the following code is:
main()
{
int a = 0;
for (; i = 0; i++)
printf("%d", a);
}





0 Nothing will be displayed Infinite loop None of the above D
The output of the following code is:
void change (char *k)
{
k="Hello";
return;
}
main()
{
char *ch = "World";;
change(ch);
printf("%s", ch);
}




Hello World Compilation error Hello World B
Which of the following is not an infinite loop




int i =1;
while (1)
{i++;}
for( ; ; ); int true=0, false;
while (true)
{false = 1;}
int y, x = 0;
do
{y = x;}
while (x==0);
C
do-while loop is useful when we want the statements within the loop must be executed


Only once At least once More than Once Any one of the above B
Which of the following is not a preprocessor directive




#if #elseif #undef #pragma B
The output of the following code is:
main()
{
int a = 5, b = 6;
(a == b? printf("%d", a));
}



0 5 Error None of the above C
The output of the following code is:
main()
{
int k, num = 30;
k = (num > 5 ? (num <= 10 ? 100 : 200) : 500);
printf("\n%d", num);
}



200 500
30 Unpredictable C
The output of the following code is:
main()
{
void msg()
{
printf("HELLO WORLD");
}
}


HELLO WORLD Error
None of the above B
The output of the following code is:
main()
{
int sub[50];
for(i=0; i<=48;i++)
{
sub[i]=i;
printf("\n%d", sub[i]);
}
}




0 to 48 will be displayed 48 49 Compilation Error D
The output of the following code is:
main()
{
int a[10], i;
for (i = 1; I <= 0; i++)
{
scanf("%d", a[i]);
printf("%d", a[i]);
}
}



10
Logical error Runtime error 1 to 10 will be displayed B
Which of the following expressions is wrong




float a =123.56; char ch ='T' * 'A'; char ch ='T' *20; 3 +a = b; D
strcat() function ----------------------- two strings. delete concatenate compare none of the above B
A function to be called must be ended with a----------------
. ? ; none of the above C
The function fopen() on failure returns---------------------. 0 NULL 1 none of the above B
The-------------------- statement helps immediate exit from any part of the loop break continue exit All of the above A
The -------------------------- loop executes at least once. for while do-while while & do-while C
char *s[10] defines an array of ------------------------ pointers to strings string to pointer both A
A multidimensional array A[10][9] can store-------- number of elements 91 88 90 89 C
The size of signed integer is ------ bytes. 4 2 8 10 B
There are total ------ numbers of operators in 'C'. 35 45 55 40 B
------ is the ternary operator ?,- ?,: ++,-- none of the above B
unsigned char has a range from 0 to ------------ 253 254 255 256 C
If 'str' is a string of 7 characters, the statement printf("%4s", str); will display ------characters.
4 7 6 0 A