Top 115 C Programming Interview Questions & Answers

 1. What does static variable mean?

Ans: Static variables are the variables which keep their values between the characteristic calls. They are initialized solely as soon as their scope is inside the characteristic in which they are defined.


2. What is a pointer?

Ans: Pointers are variables which shops the tackle of every other variable. That variable may additionally be a scalar (including some other pointer), or an combination (array or structure). The pointed-to object might also be phase of a large object, such as a subject of a shape or an factor in an array.


3. What are the makes use of of a pointer?

Ans: Pointer is used in the following cases:

  • i) It is used to get admission to array elements
  • ii) It is used for dynamic reminiscence allocation.
  • iii) It is used in Call via reference
  • iv) It is used in records buildings like trees, graph, linked listing etc.


4. What is a structure?

Ans: Structure constitutes a incredible information kind which represents various distinct information sorts in a single unit. A shape can be initialized if it is static or global.


5. What is a union?

Ans: Union is a series of heterogeneous information kind however it makes use of efficient reminiscence utilization approach through allocating adequate reminiscence to keep the greatest member. Here a single region of reminiscence incorporates values of one of a kind kinds at exceptional time. A union can by no means be initialized.




6. What are the variations between constructions and union?

Ans: A shape variable carries every of the named members, and its measurement is massive adequate to preserve all the members. Structure factors are of equal size.

A union carries one of the named participants at a given time and is massive ample to preserve the greatest member. Union issue can be of special sizes.


7. What are the variations between constructions and arrays?

Ans: Structure is a series of heterogeneous facts kind however array is a collection of homogeneous facts types.

Array:

  • 1-It is a series of statistics objects of identical statistics type.
  • 2-It has statement only
  • 3-.There is no keyword.
  • 4- array identify characterize the tackle of the beginning element.

Structure:

  • 1-It is a series of records gadgets of extraordinary facts type.
  • 2- It has statement and definition
  • 3- key-word struct is used
  • 4-Structure title is acknowledged as tag it is the quick hand notation of the declaration.


8. In header archives whether or not features are declared or defined?

Ans: Functions are declared inside header file. That is characteristic prototypes exist in a header file,not feature bodies. They are described in library (lib).


9. What are the variations between malloc ( ) and calloc ( )?

Ans: 

Malloc:

  •  1-Malloc takes one argument Malloc(a);where a wide variety of bytes 
  • 2-memory allotted incorporates rubbish values.

Calloc:

  • 1-Calloc takes two arguments Calloc(b,c) the place b no of object and c measurement of object.
  • 2-It initializes the includes of block of reminiscence to zerosMalloc takes one argument, reminiscence allotted includes rubbish values.

It allocates contiguous reminiscence locations. Calloc takes two arguments, reminiscence allotted carries all zeros, and the reminiscence allotted is now not contiguous.


10. What are macros? What are its blessings and disadvantages?

Ans: Macros are abbreviations for prolonged and often used statements. When a macro is referred to as the whole code is substituted through a single line although the macro definition is of quite a few lines.

The gain of macro is that it reduces the time taken for manipulate switch as in case of

function.

The downside of it is right here the whole code is substituted so the application becomes

lengthy if a macro is known as various times.


11. Difference between omit by means of reference and ignore by using value?

Ans: Pass by way of reference passes a pointer to the value. This permits the callee to adjust the variable directly.Pass by means of price offers a reproduction of the price to the callee. This permits the callee to alter the fee besides editing the variable. (In other words, the callee certainly cannot adjust the variable, for the reason that it lacks a reference to it.)


12. What is static identifier?

Ans: A file-scope variable that is declared static is seen solely to features inside that file. function-scope or block-scope variable that is declared as static is seen solely inside that scope. Furthermore, static variables solely have a single instance. In the case of function- or block-scope variables, this ability that the variable is now not “automatic” and for that reason retains its price throughout characteristic invocations.


13. Where is the auto variables stored?

Ans: Auto variables can be saved anywhere, so lengthy as recursion works. Practically, they’re saved on the stack. It is now not crucial that usually a stack exist. You may want to theoretically allocate characteristic invocation archives from the heap.


14. Where does global, static, and local, register variables, free reminiscence and C Program guidelines get stored?

Ans: Global: Wherever the linker places them. Typically the “BSS segment” on many platforms.

Static: Again, anywhere the linker places them. Often, they’re intermixed with the globals. The solely distinction between globals and statics is whether or not the linker will get to the bottom of the symbols throughout compilation units.Local: Typically on the stack, until the variable receives register allotted and in no way spills.Register: Nowadays, these are equal to “Local” variables. They stay on the stack except they get register-allocated.


15. Difference between arrays and linked list?

Ans: An array is a repeated sample of variables in contiguous storage. A linked listing is a set of structures scattered via memory, held collectively by way of pointers in every component that factor to the subsequent element. With an array, we can (on most architectures) go from one thing to the subsequent by means of including a constant regular to the integer price of the pointer. With a linked list, there is a “next” pointer in every shape which says what issue comes next.


16. What are enumerations?

Ans: They are a listing of named integer-valued constants. 

Example: enum coloration { black , orange=4, yellow, green, blue, violet };This assertion defines the symbols “black”, “orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc. The distinction between an enumeration and a macro is that the enum certainly broadcasts a type, and consequently can be kind checked.


17. Describe about storage allocation and scope of global, extern, static, nearby and register variables?

Ans: Globals have application-scope. They’re on hand in any compilation unit that consists of an appropriate announcement (usually delivered from a header file). They’re saved at any place the linker places them, commonly a location referred to as the “BSS segment.”

Extern? This is genuinely “global.”

Static: Stored the equal region as globals, typically, however solely on hand to the compilation unit that includes them. If they are block-scope global, solely handy inside that block and its subblocks.

Local: Stored on the stack, typically. Only accessible in that block and its subblocks.(Although pointers to locals can be handed to features invoked from inside a scope the place that neighborhood is valid.)

Register: See tirade above on “local” vs. “register.” The solely distinction is that the C compiler will now not let you take the tackle of some thing you’ve declared as “register.”


18. What are register variables? What are the benefits of the usage of register variables?

Ans: If a variable is declared with a register storage class,it is acknowledged as register variable.The register variable is saved in the cpu register as an alternative of predominant memory.Frequently used variables are declared as register variable as it’s get entry to time is faster.


19. What is the use of typedef?

Ans: The typedef assist in less complicated amendment when the applications are ported to any other machine.

A descriptive new identify given to the present information kind may also be less difficult to apprehend the code.


20. Can we specify variable discipline width in a scanf( ) structure string? If viable how?

Ans: All subject widths are variable with scanf( ). You can specify a most area width for a given field by way of setting an integer fee between the ‘%’ and the area kind specifier. (e.g. %64s). Such a specifier will nonetheless be given a narrower area width.

The one exception is %#c (where # is an integer). This reads EXACTLY # characters, and it is the only way to specify a constant area width with scanf( ).


21. Out of fgets( ) and gets( ) which characteristic is secure to use and why?

Ans: fgets( ) is safer than gets( ), due to the fact we can specify a most enter length. Neither one is definitely safe, due to the fact the compiler can’t show that programmer won’t overflow the buffer he pass by to fgets ( ).


22. Difference between strdup and strcpy?

Ans: Both reproduction a string. strcpy needs a buffer to reproduction into. strdup allocates a buffer the usage of malloc( ).

Unlike strcpy( ), strdup( ) is no longer distinctive by way of ANSI .


23. What is recursion?

Ans: A recursion characteristic is one which calls itself both without delay or in a roundabout way it should halt at a precise factor to keep away from endless recursion.


24. Differentiate between for loop and a whilst loop? What are it uses?

Ans: For executing a set of statements constant range of instances we use for loop whilst when the wide variety of iterations to be carried out is no longer acknowledged in develop we use whilst loop.


25. What is storage class? What are the unique storage instructions in C?

Ans: Storage classification is an attribute that adjustments the conduct of a variable. It controls the lifetime, scope and linkage. The storage training in c are auto, register, and extern, static, typedef.


26. What the blessings of the usage of Unions?

Ans: When the C compiler is allocating reminiscence for unions it will usually reserve adequate room for the largest member.


27. What is the distinction between Strings and Arrays?

Ans: String is a sequence of characters ending with NULL .it can be dealt with as a one dimensional array of characters terminated with the aid of a NULL character.


28. What is a a long way pointer? Where we use it?

Ans: In giant information mannequin (compact, large, huge) the address B0008000 is ideal due to the fact in these model all pointers to records are 32bits long. If we use small statistics model(tiny, small, medium) the above tackle won’t work considering the fact that in these mannequin every pointer is 16bits long. If we are working in a small facts mannequin and prefer to get entry to the tackle B0008000 then we use some distance pointer. Far pointer is constantly handled as a 32bit pointer and incorporates a phase tackle and offset tackle each of 16bits each. Thus the tackle is represented the usage of section : offset layout B000h:8000h. For any given reminiscence tackle there are many viable some distance tackle phase : offset pair. The section register consists of the tackle the place the phase starts and offset register includes the offset of data/code from the place phase begins.


29. What is a large pointer?

Ans: Huge pointer is 32bit lengthy containing section tackle and offset address. Huge pointers are normalized pointers so for any given reminiscence tackle there is solely one viable big tackle segment: offset pair. Huge pointer arithmetic is doe with calls to one of a kind subroutines so its arithmetic slower than any different pointers.


30. What is a normalized pointer, how do we normalize a pointer?

Ans: It is a 32bit pointer, which has as a great deal of its cost in the section register as possible. Since a phase can begin each 16bytes so the offset will have a cost from zero to F. for normalization convert the tackle into 20bit tackle then use the 16bit for phase tackle and 4bit for the offset address. Given a pointer 500D: 9407,we convert it to a 20bitabsolute tackle 549D7,Which then normalized to 549D:0007.


31. What is close to pointer?

Ans: A close to pointer is sixteen bits long. It makes use of the contemporary content material of the CS (code segment) register (if the pointer is pointing to code) or present day contents of DS (data segment) register (if the pointer is pointing to data) for the phase part, the offset section is saved in a sixteen bit close to pointer. Using close to pointer limits the data/code to 64kb segment.


32. In C, why is the void pointer useful? When would you use it?

Ans: The void pointer is beneficial due to the fact it is a widespread pointer that any pointer can be solid into and back once more barring loss of information.


33. What is a NULL Pointer? Whether it is identical as an uninitialized pointer?

Ans: Null pointer is a pointer which factors to nothing however uninitialized pointer may additionally factor to anywhere.


34. Are pointers integer?

Ans: No, pointers are now not integers. A pointer is an address. It is a tremendous number.


35. What does the error ‘Null Pointer Assignment’ potential and what motives this error?

Ans: As null pointer factors to nothing so gaining access to a uninitialized pointer or invalid vicinity may additionally reason an error.


36. What is ordinary pointer in C?

Ans: In C void* acts as a typical pointer. When different pointer sorts are assigned to conventional pointer, conversions are utilized mechanically (implicit conversion).


37. Are the expressions arr and &arr identical for an array of integers?

Ans: Yes for array of integers they are same.


38. IMP>How pointer variables are initialized?

Ans: Pointer variables are initialized through one of the following ways.

  • I. Static reminiscence allocation
  • II. Dynamic reminiscence allocation


39. What is static reminiscence allocation?

Ans: Compiler allocates reminiscence area for a declared variable. By the use of the tackle of operator, the reserved tackle is acquired and this tackle is assigned to a pointer variable. This way of assigning pointer cost to a pointer variable at compilation time is recognized as static reminiscence allocation.


40. What is dynamic reminiscence allocation?

Ans: A dynamic reminiscence allocation makes use of features such as malloc() or calloc( ) to get reminiscence dynamically. If these features are used to get reminiscence dynamically and the values again with the aid of these feature are assigned to pointer variables, such a way of allocating reminiscence at run time is recognized as dynamic reminiscence allocation.


41. What is the cause of realloc?

Ans: It will increase or decreases the measurement of dynamically allotted array. The feature realloc (ptr,n) makes use of two arguments. The first argument ptr is a pointer to a block of reminiscence for which the dimension is to be altered. The 2d argument specifies the new size. The dimension may additionally be extended or decreased. If ample area is now not reachable to the historic location the feature may also create a new region.


42. What is pointer to a pointer?

Ans: If a pointer variable factors any other pointer value. Such a state of affairs is recognized as a pointer to a pointer.

Example:

        int *p1,**p2,v=10;

        P1=&v; p2=&p1;

        Here p2 is a pointer to a pointer.


43. What is an array of pointers?

Ans: If the factors of an array are addresses, such an array is referred to as an array of pointers.


44. Difference between linker and linkage?

Ans: Linker converts an object code into an executable code with the aid of linking collectively the imperative constructed in functions. The structure and location of assertion the place the variable is declared in a application decide the linkage of variable.


45. Is it viable to have terrible index in an array?

Ans: Yes it is feasible to index with terrible cost supplied there are information saved in this location. Even if it is unlawful to refer to the factors that are out of array bounds, the compiler will no longer produce error due to the fact C has no test on the bounds of an array.


46. Why is it imperative to provide the measurement of an array in an array declaration?

Ans: When an array is declared, the compiler allocates a base tackle and reserves ample house in memory for all the factors of the array. The dimension is required to allocate the required house and therefore dimension ought to be mentioned.


47. What modular programming?

Ans: If a application is large, it is subdivided into a variety of smaller applications that are referred to as modules or subprograms. If a complicated trouble is solved the usage of extra modules, this method is recognized as modular programming.


48. What is a function?

Ans: A giant software is subdivided into a range of smaller packages or subprograms. Each subprogram specifies one or greater moves to be carried out for the large program. Such sub applications are referred to as functions.


49. What is an argument?

Ans: An argument is an entity used to ignore information from the calling to a referred to as function.


50. What are constructed in functions?

Ans: The features that are predefined and furnished alongside with the compiler are recognized as built-in functions. They are additionally acknowledged as library functions.


51. Difference between formal argument and genuine argument?

Ans: Formal arguments are the arguments handy in the feature definition. They are preceded by their very own statistics type. Actual arguments are handy in the characteristic call. These arguments are given as constants or variables or expressions to bypass the values to the function.


52. Is it viable to have extra than one main( ) feature in a C software ?

Ans: The feature main( ) can show up solely once. The software execution begins from main.


53. What is the distinction between an enumeration and a set of pre-processor # defines?

Ans: There is rarely any distinction between the two, barring that #defines has a international impact (throughout the file) whereas an enumeration can have an impact neighborhood to the block if desired. Some blessings of enumeration are that the numeric values are mechanically assigned whereas in #define we have to explicitly outline them. A drawback is that we have no manage over the measurement of enumeration variables.


54. How are Structure passing and returning carried out by using the complier?

Ans: When constructions are handed as argument to functions, the complete shape is usually pushed on the stack. To keep away from this overhead many programmer frequently choose to omit pointers to shape as an alternative of genuine structures. Structures are frequently again from features in a area pointed to with the aid of an extra, compiler-supported ‘hidden’ argument to the function.


55. IMP>what is the similarity between a Structure, Union and enumeration?

Ans: All of them let the programmer to outline new information type.


56. Can a Structure incorporate a Pointer to itself?

Ans: Yes such constructions are referred to as self-referential structures.


57. How can we read/write Structures from/to records files?

Ans: To write out a shape we can use fwrite( ) as Fwrite( &e, sizeof(e),1,fp);Where e is a structure variable. A corresponding fread( ) invocation can study the shape again from file. calling fwrite( ) it writes out sizeof(e) bytes from the tackle &e. Data archives written as reminiscence photos with fwrite( ),however ,will no longer be portable, specifically if they comprise floating factor fields or Pointers. This is due to the fact reminiscence sketch of constructions is computer and compiler dependent. Therefore, constructions written as reminiscence photographs can't always be examine again via packages jogging on different machine, and this is the vital issue if the records documents you’re writing will ever be interchanged between machines.


58. Write a application which employs Recursion?

Ans: int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; }


59.Write a software which makes use of Command Line Arguments?

Ans:

        #include

        void main(int argc,char *argv[])

        {

            int i;

            clrscr( );

            for(i=0;i

            printf(“\n%d”,argv[i]);

        }


60. Difference between array and pointer?

Ans:


Array:

  • 1- Array allocates area automatically
  • 2- It can't be resized
  • 3- It can't be reassigned
  • 4- sizeof (array name) offers the variety of bytes occupied through the array.


Pointer:

  • 1-Explicitly assigned to factor to an allotted space.
  • 2-It can be sized the usage of realloc()
  • 3-pointer can be reassigned.
  • 4-sizeof (p) returns the variety of bytes used to keep the pointer variable p.



61. What do the ‘c’ and ‘v’ in argc and argv stand for?

Ans: The c in argc(argument count) stands for the quantity of command line argument the application is invoked with and v in argv(argument vector) is a pointer to an array of persona string that incorporate the arguments.


62. IMP>what are C tokens?

Ans: There are six instructions of tokens: identifier, keywords, constants, string literals, operators and different separators.


63. What are C identifiers?

Ans: These are names given to more than a few programming thing such as variables, function, arrays.It is a aggregate of letter, digit and underscore.It ought to commence with letter. Backspace is no longer allowed.


64. Difference between syntax vs logical error?

Ans:

Syntax Error:

  • 1-These includes validation of syntax of language.
  • 2-compiler prints diagnostic message.

Logical Error:

  • 1-logical error are triggered via an improper algorithm or by means of a announcement mistype in such a way that it doesn’t violet syntax of language.
  • 2-difficult to find.


65. What is pre-increment and put up increment?

Ans: ++n (pre increment) increments n earlier than its price is used in an challenge operation or any expression containing it. n++ (post increment) does increment after the fee of n is used.


66. Write a software to interchange two variables besides the use of the 0.33 one.

Ans:

        a ^= b; ie a=a^b

        b ^= a; ie b=b^a;

        a ^= b ie a=a^b;

here the numbers are transformed into binary and then xor operation is performed.

You know, you’re just asking “have you considered this overly sensible trick that’s now not well worth making use of on modern architectures and solely truly applies to integer variables?”


67. What is the most mixed size of command line arguments together with the area between adjoining arguments?

Ans: It relies upon on the running system.


68. What are bit fields? What is the use of bit fields in a Structure declaration?

Ans: A bit area is a set of adjoining bits inside a single implementation primarily based storage unit that we will call a “word”.

The syntax of area definition and get entry to is primarily based on structure.

        Struct {

        unsigned int ok :1;

        unsigned int l :1;

        unsigned int m :1;

        }flags;

the wide variety following the colon represents the subject width in bits.Flag is a variable that includes three bit fields.


69. What is a pre-processor, what are the benefits of pre-processor?

Ans: A pre-processor approaches the supply code application earlier than it passes via the compiler.

  • 1- a pre-processor entails the readability of program.
  • 2- It helps simpler modification.
  • 3- It helps in writing portable programs.
  • 4- It permits less complicated debugging.
  • 5- It allows trying out a phase of program.
  • 6- It helps in creating generalized program.


70. What are the services supplied via pre-processor?

Ans:

  • 1-file inclusion
  • 2-substitution facility
  • 3-conditional compilation


71. What are the two types of #include directive?

Ans:

            1.#include”filename”

            2.#include

the first structure is used to search the listing that incorporates the supply file.If the search fails in the domestic listing it searches the implementation described locations.In the 2d shape ,the pre-processor searches the file solely in the implementation described locations.


72. How would you use the features randomize() and random()?

Ans:

Randomize( ) initiates random variety technology with a random value.

Random( ) generates random wide variety between zero and n-1;


73. What do the features atoi(), itoa() and gcvt() do?

Ans:

  • atoi( ) is a macro that converts integer to character.
  • itoa( ) It converts an integer to string.
  • gcvt( ) It converts a floating factor quantity to string.


74. How would you use the features fseek(), freed(), fwrite() and ftell()?

Ans:

  • fseek(f,1,i) Move the pointer for file f a distance 1 byte from place i.
  • fread(s,i1,i2,f) Enter i2 dataitems,each of measurement i1 bytes,from file f to string s.
  • fwrite(s,i1,i2,f) ship i2 statistics items,each of measurement i1 bytes from string s to file f.
  • ftell(f) Return the present day pointer function inside file f.

The records kind again for features fread,fseek and fwrite is int and ftell is lengthy int.


75. What is the distinction between the features memmove( ) and memcpy( )?

Ans: The arguments of memmove( ) can overlap in memory. The arguments of memcpy( ) cannot.


76. What is a file?

Ans: A file is a vicinity of storage in challenging disks or in auxiliary storage devices.It includes bytes of  information .It is no longer a records type.


77. IMP>what are the kinds of file?

Ans: Files are of two types:

  • 1-high stage archives (stream oriented files) :These documents are accessed the usage of library functions.
  • 2-low stage files(system oriented files) :These documents are accessed the usage of device calls.


78. IMP>what is a stream?

Ans: A flow is a supply of records or vacation spot of statistics that may also be related with a disk or other I/O device. The supply movement gives facts to a software and it is recognized as enter stream. The vacation spot circulation receives the output from the software and is acknowledged as output stream.


79. What is supposed by using file opening?

Ans: The motion of connecting a software to a file is known as opening of a file. This requires creating an I/O circulate earlier than analyzing or writing the data.


80. What is FILE?

Ans: FILE is a predefined statistics type. It is described in stdio.h file.


81. What is a file pointer?

Ans: The pointer to a FILE statistics kind is referred to as as a move pointer or a file pointer. A file pointer factors to the block of data of the circulation that had simply been opened.


82. How is fopen()used ?

Ans: The feature fopen() returns a file pointer. Hence a file pointer is declared and it is assigned as

        FILE *fp;

        fp= fopen(filename,mode);

filename is a string representing the identify of the file and the mode represents:

  • “r” for study operation.
  • “w” for write operation.
  • “a” for append operation.
  • “r+”,”w+”,”a+” for replace operation.


83. How is a file closed ?

Ans: A file is closed the use of fclose() function

        Eg. fclose(fp);

Where fp is a file pointer.


84. What is a random get entry to file?

Ans: A file can be accessed at random the usage of fseek( ) function

        fseek(fp,position,origin);

fp is a file pointer.

position range of bytes offset from origin:

origin 0,1 or two denote the starting ,current function or quit of file respectively.


85. What is the reason of ftell ?

Ans: The feature ftell() is used to get the contemporary file represented through the file pointer.

        ftell(fp);

returns a lengthy integer price representing the cutting-edge file role of the file pointed by means of the file pointer fp.If an error takes place ,-1 is returned.


86. What is the cause of rewind() ?

Ans: The feature rewind is used to convey the file pointer to the establishing of the file.

        Rewind(fp);

Where fp is a file pointer.Also we can get the equal impact by

        feek(fp,0,0);


87. Difference between a array identify and a pointer variable?

Ans: A pointer variable is a variable the place as an array identify is a constant tackle and is now not a variable. A pointer variable need to be initialized however an array identify can't be initialized. An array title being a regular cost , ++ and — operators can't be utilized to it.


88. Represent a two-dimensional array the use of pointer?

Ans:

        Address of a[I][j] Value of a[I][j]

        &a[I][j]

    or

        a[I] + j

    or

        *(a+I) + j

        *&a[I][j] or a[I][j]

    or

        *(a[I] + j )

    or

        *( * ( a+I) +j )


89. Difference between an array of pointers and a pointer to an array?

Ans:

Array of pointers:

  • 1- Declaration is: data_type *array_name[size];
  • 2-Size represents the row size.
  • 3- The house for columns may additionally be dynamically.

Pointers to an array:

  • 1-Declaration is data_type ( *array_name)[size];
  • 2-Size represents the column size.


90. Can we use any title in location of argv and argc as command line arguments ?

Ans: sure we can use any person described title in region of argc and argv;


91. What are the pointer declarations used in C?

Ans:

  • 1- Array of pointers, e.g , int *a[10]; Array of pointers to integer.
  • 2-Pointers to an array,e.g , int (*a)[10]; Pointer to an array of into.
  • 3-Function returning a pointer,e.g, flow *f( ) ; Function returning a pointer to float.
  • 4-Pointer to a pointer ,e.g, int **x; Pointer to apointer to int.
  • 5-pointer to a statistics kind ,e.g, char *p; pointer to char.


92. Differentiate between a regular pointer and pointer to a constant?

Ans:

  • const char *p; //pointer to a const character.
  • char const *p; //pointer to a const character.
  • char * const p; //const pointer to a char variable.
  • const char * const p; // const pointer to a const character.


93. Is the allotted house inside a feature mechanically de-allocated when the characteristic returns?

Ans: No pointer is extraordinary from what it factors to .Local variables together with neighborhood pointers variables in a feature are de-allocated routinely when feature returns.,But in case of a local pointer variable ,de-allocation skill that the pointer is de-allocated and now not the block of memory allotted to it. Memory dynamically allotted usually persists till the allocation is freed or the software terminates.


94. Discuss on pointer arithmetic?

Ans:

  • 1- Assignment of pointers to the equal kind of pointers.
  • 2- Adding or subtracting a pointer and an integer.
  • 3-subtracting or evaluating two pointer.
  • 4-incrementing or decrementing the pointers pointing to the factors of an array. When a pointer to an integer is incremented through one , the tackle is incremented with the aid of two. It is carried out automatically by the compiler.
  • 5-Assigning the fee 0 to the pointer variable and evaluating zero with the pointer. The pointer having tackle zero factors to nowhere at all.


95. What is the invalid pointer arithmetic?

Ans:

  • i) including ,multiplying and dividing two pointers.
  • ii) Shifting or overlaying pointer.
  • iii) Addition of glide or double to pointer.
  • iv) Assignment of a pointer of one kind to a pointer of every other kind ?


96. What are the benefits of the usage of array of pointers to string rather of an array of strings?

Ans:

  • i) Efficient use of memory.
  • ii) Easier to trade the strings by using shifting their pointers whilst sorting.


97. Are the expressions *ptr ++ and ++ *ptr same?

Ans: No,*ptr ++ increments pointer and no longer the cost pointed through it. Whereas ++ *ptr increments the price being pointed to through ptr.


98. What would be the equal pointer expression foe referring the equal aspect as

a[p][q][r][s] ?

Ans : *( * ( * ( * (a+p) + q ) + r ) + s)


99. Are the variables argc and argv are constantly neighborhood to main?

Ans: Yes they are nearby to main.


100. Can major ( ) be referred to as recursively?

Ans: Yes any feature such as primary ( ) can be referred to as recursively.


101. IMP>Can we initialize unions?

Ans: ANSI Standard C approves an initializes for the first member of a union. There is no well known way of initializing any different member (nor, beneath a pre-ANSI compiler, is there usually any way of initializing a union at all).


102. What’s the distinction between these two declarations?

Ans:     struct x1 { … };

              typedef struct { … } x2;

The first shape announces a shape tag; the 2nd announces a typedef. The foremost distinction is that the 2nd statement is of a barely greater summary type.its customers don’t always comprehend that it is a structure, and the key-word struct is no longer used when declaring situations of it.


103. Why doesn’t this code: a[i] = i++; work?

Ans: The sub-expression i++ motives a aspect effect.it modifies i’s value.which leads to undefined behavior due to the fact i is additionally referenced somewhere else in the identical expression.


104. Why doesn’t struct x { … };

        x thestruct;

        work?

Ans:

C is now not C++. Typedef names are no longer robotic-ally generated for shape tags.


105. Why can’t we examine structures?

Ans: There is no single, excellent way for a compiler to put in force shape evaluation which is steady with C’s low-level flavor. A easy byte-by-byte contrast should founder on random bits current in unused “holes” in the shape (such padding is used to maintain the alignment of later fields correct). A field-by-field assessment may require unacceptable quantities of repetitive code for massive structures.


106. How are shape passing and returning implemented?

Ans: When buildings are handed as arguments to functions, the whole shape is normally pushed on the stack, the usage of as many phrases as are required. Some compilers only omit a pointer to the structure, although they can also have to make a nearby reproduction to hold pass-by-value semantics.
Structures are regularly again from features in a place pointed to by means of an extra,compiler-supplied “hidden” argument to the function. Some older compilers used a special,static area for shape returns, though this made structure-valued features non-re-entrant, which ANSI C disallows.


107. What is an instruction in computer?

Ans: An instruction is an order given to a computer processor by a computer program. In assembler language, a macro instruction is one that, during processing by the assembler program, expands to become multiple instructions (based on a previously coded macro definition).

108. Difference between arrays and linked list?

Ans: An array is a repeated pattern of variables in contiguous storage. A linked list is a set of structures scattered through memory, held together by pointers in each element that point to the next element. With an array, we can (on most architectures) move from one element to the next by adding a fixed constant to the integer value of the pointer. With a linked list, there is a ―next pointer in each structure that says what element comes next.


109. What is a generic pointer in C?
Ans: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer, conversions are applied automatically (implicit conversion).


110. What is the maximum combined length of command line arguments including the space between adjacent arguments?

 Ans: It depends on the operating system.


111. What are bit fields? What is the use of bit fields in a Structure declaration? 

Ans: A bit field is a set of adjacent bits within a single implementation based storage unit that we will call a ―word‖. The syntax of field definition and access is based on structure. Struct { unsigned int k :1; unsigned int l :1; unsigned int m :1; }flags; the number following the colon represents the field width in bits. The flag is a variable that contains three-bit fields.


112. How would you use the functions randomize( ) and random( )? 

Ans: Randomize( ) initiates random number generation with a random value. Random( ) generates a random number between 0 and n-1;


113. What is the purpose of rewind( )? 

Ans: The function rewind is used to bring the file pointer to the beginning of the file. Rewind(fp); Where fp is a file pointer. Also, we can get the same effect by feel(fp,0,0); 


114. Is the allocated space within a function automatically de-allocated when the function returns? 

Ans: No pointer is different from what it points to.Local variables including local pointers variables in a function are de-allocated automatically when the function returns., But in the case of a local pointer variable, de-allocation means that the pointer is de-allocated and not the block of memory allocated to it. Memory dynamically allocated always persists until the allocation is freed or the program terminates.

 

115. What is the scale factor in c?

Ans: The step in which the ptr is increased or reduced is called the scale factor. The scale factor is nothing but the size of the data type used in a computer.

Post a Comment

0 Comments