C Functions

  Home  C Language  C Functions


“C Language Functions frequently Asked Questions in various C functions job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”



45 C Functions Questions And Answers

23⟩ Tell me what is the purpose of "register" keyword in C Language?

The keyword ‘register’ instructs the compiler to persist the variable that is being declared , in a CPU register.

Ex: register int number;

The persistence of register variables in CPU register is to optimize the access. Even the optimization is turned off; the register variables are forced to store in CPU register.

 202 views

24⟩ Do you know the purpose of "register" keyword?

It is used to make the computation faster.

The register keyword tells the compiler to store the variable onto the CPU register if space on the register is available. However, this is a very old technique. Todays processors are smart enough to assign the registers themselves and hence using the register keyword can actually slowdown the operations if the usage is incorrect.

 190 views

25⟩ Do you know the use of "auto" keyword?

When a certain variable is declared with the keyword 'auto' and initialized to a certain value, then within the scope of the variable, it is reinitialized upon being called repeatedly.

 235 views

26⟩ What are the scope of static variables?

The scope of a static variable is local to the block in which the variable is defined. However, the value of the static variable persists between two function calls.

 233 views

27⟩ Do you know what are the properties of Union in C?

A union is utilized to use same memory space for all different members of union. Union offers a memory section to be treated for one variable type , for all members of the union. Union allocates the memory space which is equivalent to the member of the union , of large memory occupancy.

 211 views

28⟩ What is use of bit field?

Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage is at a premium.

 236 views

29⟩ Explain bitwise shift operators?

The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator.

 231 views

32⟩ What is memcpy() function?

With memcopy(), the programmer needs to specify the size of data to be copied. strncpy() is similar to memcopy() in which the programmer specifies n bytes that need to be copied.

 238 views

37⟩ Explain the use of "auto" keyword in C Programming?

The keyword ‘auto’ is used extremely rare. A variable is set by default to auto. The declarations:

auto int number; and int number;

has the same meaning. The variables of type static, extern and register need to be explicitly declared, as their need is very specific. The variables other than the above three are implied to be of ‘auto’ variables. For better readability auto keyword can be used.

 233 views

38⟩ What is self-referential structure in C Programming?

A self-referential structure is one of the data structures which refer to the pointer to (points) to another structure of the same type. For example, a linked list is supposed to be a self-referential data structure. The next node of a node is being pointed, which is of the same struct type. For example,

typedef struct listnode {

void *data;

struct listnode *next;

} linked_list;

In the above example, the listnode is a self-referential structure – because the *next is of the type sturct listnode.

 270 views

39⟩ What is the scope of static variables in C Language?

Static variables in C have the scopes;

1. Static global variables declared at the top level of the C source file have the scope that they can not be visible external to the source file. The scope is limited to that file.

2. Static local variables declared within a function or a block, also known as local static variables, have the scope that, they are visible only within the block or function like local variables. The values assigned by the functions into static local variables during the first call of the function will persist / present / available until the function is invoked again.

The static variables are available to the program, not only for the function / block. It has the scope within the current compile. When static variable is declared in a function, the value of the variable is preserved , so that successive calls to that function can use the latest updated value. The static variables are initialized at compile time and kept in the executable file itself. The life time extends across the complete run of the program.

Static local variables have local scope. The difference is, storage duration. The values put into the local static variables, will still be present, when the function is invoked next time.

 264 views

40⟩ What is C Programming structure?

Structures provide a convenient method for handling related group of data of various data types.

Structure definition:

struct tag_name

{

data type member1;

data type member2;

}

Example:

struct library_books

{

char title[20];

char author[15];

int pages;

float price;

};

The keyword struct informs the compiler for holding fields ( title, author, pages and price in the above example). All these are the members of the structure. Each member can be of same or different data type.

The tag name followed by the keyword struct defines the data type of struct. The tag name library_books in the above example is not the variable but can be visualized as template for the structure. The tag name is used to declare struct variables.

Ex: struct library_books book1,book2,book3;

The memory space is not occupied soon after declaring the structure, being it a template. Memory is allocated only at the time of declaring struct variables, like book1 in the above example. The members of the structure are referred as - book1.title, book1.author, book1.pages, book1.price.

Unions

Unions are like structures, in which the individual data types may differ from each other. All the members of the union share the same memory / storage area in the memory. Every member has unique storage area in structures. In this context, unions are utilized to observe the memory space. When all the values need not assign at a time to all members, unions are efficient. Unions are declared by using the keyword union , just like structures.

Ex: union item {

int code;

float price;

};

The members of the unions are referred as - book1.title, book1.author, book1.pages, book1.price.

 238 views