RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Actually this happens due to instruction involvement in these operation. n++ requires a single instruction whereas n+1 requires more than one instruction to perform this operation.
n++ requires only inc instruction whereas n+1 first load value in to register then use add instruction to add value 1 in to that register and then finally store in to accumulator. but in n++ a single instruction does all.
return statement returns only one variable at at time. It is a restriction of returning multiple item through return statement. pointers provide solution for this problem. Placing pointer to different return types, it is possible to return multiple items. Struct is group of heterogeneous elements. if we return structure through return statement we can return multiple items as structure member.
Inline function is used to reduce the overhead of call and return sequence of a function. using inline keyword we make a function inline. Ex- inline int add(int a, int b) { return (a+b); } if we call add() function from any part of our code the caller function is replaced bu its function body. You can use inline for optimization of your code. When some function requires frequent call you can use inline.
Why n++ executes faster than n+1?
ReplyDeleteActually this happens due to instruction involvement in these operation. n++ requires a single instruction whereas n+1 requires more than one instruction to perform this operation.
Deletehow can we check ,n+1 is taken more tnan one instruction?
ReplyDeleten++ requires only inc instruction whereas n+1 first load value in to register then use add instruction to add value 1 in to that register and then finally store in to accumulator. but in n++ a single instruction does all.
ReplyDeleteThere is also other reason to work n++ faster .unary operator execute faster than binary operator.
ReplyDeleteThanks a lot for clarify this question...
DeleteWhat is difference between function overloading and operator overloading?
ReplyDeleteHello Ritesh, As per my knowledge C does not have any support for function overloading and operator overloading
DeleteGive a example, In which function returning pointer to structure and where to be use and also what is benefits ?
ReplyDeletereturn statement returns only one variable at at time. It is a restriction of returning multiple item through return statement. pointers provide solution for this problem. Placing pointer to different return types, it is possible to return multiple items.
DeleteStruct is group of heterogeneous elements. if we return structure through return statement we can return multiple items as structure member.
Bhaiya i understood the theory but can you give a example..
Deletetypedef struct _record
Delete{
int sn;
char name[20];
char add[100];
double age;
}record;
record *add_record()
{
record *item = (record *)malloc(sizeof(record));
/*
* Filling recoed items
*/
/* ........
........
........
*/
return item;
}
This one example where function is returning pointer to structure
Thanks a lot ..:)
DeleteExplain with example inline function and where to be use and what is advantage ?
ReplyDeleteInline function is used to reduce the overhead of call and return sequence of a function. using inline keyword we make a function inline.
DeleteEx-
inline int add(int a, int b)
{
return (a+b);
}
if we call add() function from any part of our code the caller function is replaced bu its function body.
You can use inline for optimization of your code. When some function requires frequent call you can use inline.
How to find pivot in quick sort ?
ReplyDelete