Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 08

C Language Interview Question and Answers:

36. What is the difference between const charp and char const p?
      const charp - p is pointer to the constant character. i.e value in that address location is constant.
const char const p - p is the constant pointer which points to the constant string, both value and address are constants.



37. What is a pointer value and address?
      A pointer value is a data object that refers to a memory location. Each memory location is numbered in the memory. The number attached to a memory location is called the address of the location.

38. What is the difference between a string copy (strcpy) and a memory copy (memcpy)?
      The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved.
On the other hand, the memcpy() function is designed to work with any type of data. Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination.

 
39. What is the purpose of realloc()?
         Realloc(ptr,n) function uses two arguments.
    The first argument ptr is a pointer to a block of memory for which the size is to be altered.
    The second argument n specifies the new size.The size may be increased or decreased.


40. What is the difference between a NULL Pointer and a NULL Macro?
      Null pointer is a pointer that is pointing nothing while NULL macro will used for replacing 0 in program as define NULL 0 .

LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 20

Language C Interview

C Language Interview Question and Answers:

96. What is the invalid pointer arithmetic?             
    adding ,multiplying and dividing two pointers.
    Shifting or masking pointer.
    Addition of float or double to pointer
    Assignment of a pointer of one type to a pointer of another type


97. What are the pointer declarations used in C?
     Array of pointers, e.g , int *a[10]; Array of pointers to integer
    Pointers to an array,e.g , int (*a)[10]; Pointer to an array of into
    Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float
    Pointer to a pointer ,e.g, int **x; Pointer to apointer to int
    pointer to a data type ,e.g, char *p; pointer to char

LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 19

Language C Interview

C Language Interview Question and Answers:

91. What is a file pointer?
                The pointer to a FILE data type is called as a stream pointer or a file pointer. A file pointer points to the block of information of the stream that had just been opened.

92. what is a stream?
                A stream is a source of data or destination of data that may be associated with a disk or other I/O device. The source stream provides data to a program and it is known as input stream. The destination stream eceives the output from the program and is known as output stream.

93. What is the difference between the functions memmove( ) and memcpy( )?
                The arguments of memmove( ) can overlap in memory. The arguments of memcpy( ) cannot.

94. What are the advantages of using array of pointers to string instead of an array of strings?
                Efficient use of memory.
Easier to exchange the strings by moving their pointers while sorting.

95. What is meant by file opening?
                The action of connecting a program to a file is called opening of a file. This requires creating an I/O stream before reading or writing the data.

LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 18

Language C Interview

C Language Interview Question and Answers:

86. What is the difference between syntax vs logical error?  
    Syntax Error
    These involves validation of syntax of language.
    compiler prints diagnostic message.

    Logical Error
    logical error are caused by an incorrect algorithm or by a statement mistyped in such a way that it doesn’t violet syntax of language.
    difficult to find.

87.     What are the two forms of #include directive?
      #include“filename”
#include - the first form is used to search the directory that contains the source file.If the search fails in the home directory it searches the implementation defined locations.In the second form ,the preprocessor searches the file only in the implementation defined locations.

88. What is preincrement and post increment?
      ++n (pre increment) increments n before its value is used in an assignment operation or any expression containing it. n++ (post increment) does increment after the value of n is used.

89. Can a Structure contain a Pointer to itself?
      Yes such structures are called self-referential structures.

90. What is the difference between array and pointer?
           Array
    Array allocates space automatically.
    It cannot be resized
    It cannot be reassigned.
    size of (arrayname) gives the number of bytes occupied by the array.

    Pointer
    Explicitly assigned to point to an allocated space.
    It can be sized using realloc() 3-pointer can be reassigned.
    sizeof (p) returns the number of bytes used to store the pointer variable p.

LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 17

Language C Interview

C Language Interview Question and Answers:

81.     What are built in functions?
      The functions that are predefined and supplied along with the compiler are known as built in functions. They are also known as library functions.

82.     What is the difference between linker and linkage?
      Linker converts an object code into an executable code by linking together the necessary built in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

83.     What is a function?
      A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for the larger program. Such sub programs are called functions.

84.     What is an argument?
      An argument is an entity used to pass data from the calling to a called function.

85.     What is pointer to a pointer?
      If a pointer variable points another pointer value. Such a situation is known as a pointer to a pointer.
Example : int *p1,
**p2,
v=10;P1=&v; p2=&p1;
Here p2 is a pointer to a pointer.