why arithmetic operation can’t be performed on a void pointer?
Answer Posted / vadivel t
Hav an example with an int pointer,
assume compiler allocates two bytes for an int.
int *iptr, iArray[3] = {1, 2, 3};
/*say the iArray starting address would be 1000*/
iptr = iArray[0];
/*When u r trying to do iptr++ then it will point to 1002
(two bytes for an int) where element 2 available.
cos compiler knows how many bytes has two increment*/
iptr++;
Now come to void:
void pointer is generic pointer which can be point to any
kind of data types.
void *ptr;
/*When u r trying to do ptr++, since it is void pointer, it
will not know exactly how many bytes has to be incremented.
So that arithmatic operations not possible with void
pointer.*/
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Are local variables initialized to zero by default in c?
What is echo in c programming?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
What is a char in c?
Is struct oop?
Explain what is the difference between a free-standing and a hosted environment?
What is function prototype in c with example?
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
Is main a keyword in c?
What are keywords in c with examples?
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
Can an array be an Ivalue?
How is actual parameter different from the formal parameter?
If null and 0 are equivalent as null pointer constants, which should I use?