The greatest mistake you can make in life is to be continually fearing you will make one
Showing posts with label C Questions. Show all posts
Showing posts with label C Questions. Show all posts

Saturday, 31 July 2010

Questions on Functions

  1. Difference between pass by value and pass by reference?
  2. Can you write function similar to printf()?
  3. How can called function determine number of arguments that have been passed to it?
  4. What is the purpose of main() function?
  5. What are the advantages of functions?
  6. Define function and built-in function?
  7. Can the sizeof operator used to tell the size of an array passed to a function?
  8. Is it possible to execute a code even after the program exits the main() function?
  9. What is a static function?
  10. Why should I prototype a function?
  11. Is it better to use a function or a macro?
  12. How do you determine whether to use a stream function or a low level function?

Tuesday, 1 June 2010

Interview Questions

1. Difference between arrays and pointers?
2. What is the purpose of realloc( )?
3. What is static memory allocation and dynamic memory allocation?
4. How are pointer variables initialized?
5. Are pointers integers?
6. What is a pointer variable?
7. What is a pointer value and address?
8. What is a method?
9. What are the advantages of the functions?
10. What is the purpose of main( ) function?
11. What is an argument ? differentiate between formal arguments and actual arguments?
12. What is a function and built-in function?
13. What is modular programming?
14. When does the compiler not implicitly generate the address of the first element of an array?
15. What are the characteristics of arrays in C?
16. Differentiate between a linker and linkage?
17. What are advantages and disadvantages of external storage class?
18. Diffenentiate between an internal static and external static variable?
19. What are the advantages of auto variables?
20. What is storage class and what are storage variable ?
21. Which expression always return true? Which always return false?
22. Write the equivalent expression for x%8?
23. why n++ executes faster than n+1?
24. what is a modulus operator? What are the restrictions of a modulus operator?
25. What is the difference between a string and an array?
26. Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
27. Can the sizeof operator be used to tell the size of an array passed to a function?
28. Is using exit() the same as using return?
29. Is it possible to execute code even after the program exits the main() function?
30. What is a static function?
31. Why should I prototype a function?
32. How do you print an address?
33. Can math operations be performed on a void pointer?
34. How can you determine the size of an allocated portion of memory?
35. What is a “null pointer assignment” error? What are bus errors, memory faults, and core dumps?
36. What is the difference between NULL and NUL?
37. What is the heap?
38. Can the size of an array be declared at runtime?
39. What is the stack?
40. When should a far pointer be used?
41. What is the difference between far and near?
42. Is it better to use malloc() or calloc()?
43. Why should we assign NULL to the elements (pointer) after freeing them?
44. When would you use a pointer to a function?
45. How do you use a pointer to a function?
46. Can you add pointers together? Why would you?
47. What does it mean when a pointer is used in an if statement?
48. Is NULL always defined as 0?
49. What is a void pointer?
50. What is a null pointer?
51. How many levels of pointers can you have?
52. What is indirection?
53. How do you print only part of a string?
54. How can I convert a string to a number?
55. How can I convert a number to a string?
56. What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
57. How can you check to see whether a symbol is defined?
58. How do you override a defined macro?
59. What is #line used for?
60. What is a pragma?
61. What are the standard predefined macros?
62. How can type-insensitive macros be created?
63. How many levels deep can include files be nested?
64. Can include files be nested?
65. Can you define which header file to include at compile time?
66. What is the difference between #include and #include “file”?
67. Is it better to use a macro or a function?
68. How are portions of a program disabled in demo versions?
69. What is the benefit of using an enum rather than a #define constant?
70. What is the benefit of using #define to declare a constant?
71. Can a file other than a .h file be included with #include?
72. How can you avoid including a header more than once?
73. What will the preprocessor do for a program?
74. What is a macro, and how do you use it?
75. What is Preprocessor?
76. How can I make sure that my program is the only one accessing a file?
77. How can I open a file so that other programs can update it at the same time?
78. How do you determine whether to use a stream function or a low-level function?
79. What is the difference between text and binary modes?
80. How can you restore a redirected standard stream?
81. How do you redirect a standard stream?
82. How can I search for data in a linked list?
83. How can I sort a linked list?
84. What is hashing?
85. What is the quickest searching method to use?
86. What is the easiest searching method to use?
87. How can I sort things that are too large to bring into memory?
88. What is the quickest sorting method to use?
89. What is the easiest sorting method to use?
90. What is the benefit of using const for declaring constants?
91. Can static variables be declared in a header file?
92. What is the difference between declaring a variable and defining a variable?
93. Is it acceptable to declare/define a variable in a C header?
94. When should a type cast not be used?
95. When should a type cast be used?
96. How can you determine the maximum value that a numeric variable can hold?
97. How reliable are floating-point comparisons?
98. Can a variable be both const and volatile?
99. when should the volatile modifier be used?
100. When should the register modifier be used? Does it really help?

Thursday, 20 May 2010

Questions on Command Line Arguments

  1. What is command line argument?
  2. Are variables argc and argv are local to main?
  3. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to function?
  4. Is there any way to expand any wildcard characters present in the commandl ine arguments? If yes state that?
  5. What is the maximum length of command line arguments including space between adjacent arguments?
  6. What is 'c, and 'v' in argc and argv stand for?
  7. What is the output of the following program?
      #include < stdio.h >
    int main(int argc,char *argv[])
    {
        int i;
        argc=2;
        argv[0]="";
        argv[1]="I am a dog.Hope I am right";

        printf("Number of Arguments passed=%d\n",argc);
        for(i=0;i< argc;i++)
            printf("argv[%d]=%s\n",i,argv[i]);
        return;
    }
  8. Does the following program has any error or not?
    #include < stdio.h >
    int main(int argc,char *argv)
    {
        int x;
        x=sum(argv[1],argv[2]);
        printf("x=%d\n",x);
        return;
    }
    int sum(int x,int y)
    {
        return x+y;
    }
  9. What type is argv?
    A. char *
    B. int
    C. char **
    D. It's not a variable
     
  10. What does the argument count variable store?
    A. the number of arguments
    B. the number of arguments plus one
    C. the number of arguments minus one
    D. The total size of the argument array
     
  11. In what order do the two command line variables appear in the definition of main? A. Count then argument array
    B. Argument array then count
    C. They don't appear in the definition of main
    D. There is only one argument.
     
  12. What is argv[0]? A. The number of arguments to the program
    B. The name of the program
    C. The first argument to the program
    D. This syntax is illegal 

  13. What variables stores the number of arguments to a program?
    A. argc
    B. argv
    C count
    D. arglen





Wednesday, 12 May 2010

Questions on Structures

  1. What is a structure?
  2. How to access structure members?
  3. How to access the variable x in the following structure?
      struct s1{ struct { struct { int x; }s2 }s3 }s;
  4. Can structure contain pointer to itself?
  5. Difference between Structure and Unions?
  6. Difference between Structure and Arrays?
  7. How are structure passing and returning inplemented by compiler?
  8. How can we check whether contents of two structure variables are same or not?
  9. How can we read/write from/to data files?
  10. What are the similarities between structure,union and enumeration?
  11. Define bitfields?What is the use of bitfields in structure declaration?
  12. What are the advantages of using Structure?
  13. How will you pass a structure to a function?
  14. How will you pass an array of structures to a function?
  15. Is there any way to compare two structures automatically?
  16. Why we cannot use relational and logical operators in structure variable?
  17. 20 floats are to bestored in memory.What would you prefer,an array or a structure?
  18. state true or false for the following
    1. All structure elements are stored in contiguous memory locations
    2. In an array of structures,not only are all structures stored in contiguous memory locations,but the elements of individual structures arealso stored in contiguous locations.

    Tuesday, 11 May 2010

    Questions on Arrays

    1. Define Array?
    2. The starting location of an array is 1000.If the array[1..5/..4] is stored in a row major order form what is the location of element[4][3].Each element occupies 4 bytes.
    3. What is the size of the array declared as double *x[5]?
    4. Is the expressions arr and *arr are same for array of integers?
    5. Is it possible to allocate arrays dynamically?
    6. Difference between string and arrays?
    7. Difference between arrays and linked list?
    8. Does mentioning arrayname gives basse addressin all contexts?
    9. How can we increase the size of a dynamically allocated array?
    10. Is it possible to increase the size of statically allocated array?
    11. Difference between array and structure?
    12. How do you count just the number of elements in the array that are being used?
    13. Consider an array that can holds upto 100 elements, but only the first 20 elements are actually used.What are the values stored in the remaining elements?
    14. Write the logic for multiplying two 2 by 2 matrices and store the result in a third variable?
    15. How do you copy the elements of a 2 dimensional array in to a 1 dimensional array?
    16. Why array index is starting from zero? (or) Why arrays not store values from 1?
    17. How will you combine the elements of two integer arrays in to one single array in c language?
    18. How will you convert a 1 dimensional array in to a 2 dimensional array?
    19. How to split a string(using delimitor /) and store each portion to a separate array?
    20. What are the application of one dimensional and two dimensional arrays?
    21. Can we use heterogeneous declarations in arrays?If they are not declared what is the reason?
    22. What is the valid range of indexes for an array of 10 objects? What happens if we print the address of the 11th memory of that array?

    Monday, 10 May 2010

    Questions on Pointers

    1. What is pointer?
    2. What is NULL pointer?Is it same as uninitialized pointer?
    3. What does the error 'NULL Pointer Assignment' mean and what causes this error?
    4. Difference between NULL pointer and NULL macro?
    5. What is far pointer? Where we use it?http://www.blogger.com/post-edit.g?blogID=3012383994992801642&postID=2425531620599867473
    6. What are near,far and huge pointers? How many bytes are occupied by them?
    7. When you reallocate the memory which is currently referenced by several other pointers, do you have to readjust these other pointers or do they get readjusted automatically?
    8. Write down the equivalent pointer expression for referring the element a[i][j][k][l]?
    9. Advantages of using pointers in programs?
    10. Declare the following

      1. array of 3 pointers to chars
      2. array of 3 char pointers
      3. pointer to array of 3 chars
      4. pointer to function that receieves int pointer and returns float pointer
      5. pointer to function that receieves nothing and returns nothing
    11. How will you declare array of three function pointers where each function receives two ints and returns float?
    12. What is the size of pointer variable in C?How to calculate the size of pointer?
          size of pointer can be calculated by using sizeof() operator. Pointer stores the address of the variable. Address of variable is always an integer value. Storing integer value require 4bytes(32 bit compiler). So pointer variable require 4 bytes of memory
    13. What is the size of void pointer variable in c?
      void *ptr;
      sizeof(ptr)?
    14. What is the size of const pointer variable in C?
    15. Which pointer require more memory space int or character pointer?
          Size of pointer variable does not depends upon data type. Pointer variable only stores the address of the variable. Address is always integer value. So size of pointer variabl of any type is 4 bytes(32 bit compiler)
    16. Write the equivalent pointer expression for the following array variables?
      1. a[i][j]
      2. a[i][j][k]
      3. a[i][j][k][l]

    Friday, 12 March 2010

    C Interview Questions

    1.How to write a c program without using semicolon?
    Solution

    1.#include<stdio.h>
    main()
    {
    if(printf("Welcome")){}
    }
    output
    Welcome
    2.#include<stdio.h>
    main()
    {
    while(printf("Welcome"),0){}
    }
    output
    Welcome
    The while loop will execute until the condition is true. so the statement will print continuously to avoid that comma operator is used. The comma operator ignores the 1st argument and return the 2nd one. so the value o is given to while loop and the while loop is executed only once

    2.Write a c program to print the number of digits in a decimal number?
    #include<stdio.h>
    int main()
    {
        int n,count=0,x;
        printf("ENter the decimal number\n");
        scanf("%d",&n);
        x=n;
        while(n>0)
        {
            count++;
            n=n/10;
        }
        printf("Number %d has %d digits\n",x,count);
    }
    output
    ENter the decimal number
    2345
    Number 2345 has 4 digits

    3.Write a C program to print the two's complement of a decimal number?
     Solution
    #include<stdio.h>
    int main()
    {
        int n,x;
        printf("Enter a number\n");
        scanf("%d",&n);
        x=n;
        n=(~n)+1;
        printf("Two's complement of %d=%d",x,n);
        return 0;
    }
    Output
    Enter a number 81
    Two's complement of 81=-81