in Technology by
Can math operations be performed on a void pointer?

1 Answer

0 votes
by

According to c standard arithmetic operation on void pointers is illegal that means the C standard doesn’t allow pointer arithmetic with void pointers. However, In GNU C, addition and subtraction operations are supported on void pointers to assuming the size of the void is 1.

Let see an example

#include<stdio.h>
int main()
{
int aiData[3] = {100, 200,300};
void *pvData = &aiData[1]; //address of 200
pvData += sizeof(int);
printf("%d", *(int *)pvData);
return 0;
}

Output: 300 or compiler error.

Explanation: When we compile the code then some compiler throw the compiler error but some compiler compiled the code and print 300 as output to assume the size of the void 1.

Note: Don’t perform the arithmetic operation on the void pointer. As per the C standard sizeof is not applicable on void but in GNU C we can calculate the size of the void and sizeof operator return 1.

Related questions

0 votes
    Which are the operations can be performed on a document using Elasticsearch?...
asked Jun 3, 2021 in Technology by JackTerrance
0 votes
    What is the advantage of a void pointer in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is the size of a void pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is (void*)0? Error re of null pointer re of void pointer none of the listed options? Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Redo operations are performed exclusively using (a) Logical logging (b) Physical logging (c) Physical log ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Frequency analysis can be performed on polyalphabetic ciphers, which makes it weak. (1)False (2)True...
asked Mar 19, 2021 in Technology by JackTerrance
0 votes
    In Flash memory, the erase operation can be performed on a number of pages, called an _______ at once ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Dynamic testing can be performed on the principles of white and black box testing. (1)True (2)False...
asked Jun 1, 2021 in Education by JackTerrance
0 votes
    You can cancel the previous action performed by clicking on the _______ button from __________ Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
0 votes
    You can cancel the previous action performed by clicking on the _______ button from __________ Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    You can cancel the previous action performed by clicking on the _______ button from __________ Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    What are the different levels at which performance improvement can be performed in Informatica?...
asked Mar 27, 2021 in Technology by JackTerrance
0 votes
    Which of the following transforms can be performed with data value? (a) log2 (b) cos (c) log10 (d) ... -learning-in-Data-Science,Data-Science-Lifecycle,Applications-of-Data-Science...
asked Oct 30, 2021 in Education by JackTerrance
0 votes
    Which operator can be used to access union elements if union variable is a pointer variable?...
asked Jan 18, 2021 in Technology by JackTerrance
0 votes
    Which built-in function can be used to move the file pointer internally?...
asked Jan 18, 2021 in Technology by JackTerrance
...