in Technology by
Explain the difference between *ptr++ and ++*ptr same?

1 Answer

0 votes
by
Both expressions are different. Let’s see a sample code to understand the difference between both expressions. #include int main(void) { int aiData[5] = {100,200,30,40,50}; int *ptr = aiData; *ptr++; printf("aiData[0] = %d, aiData[1] = %d, *piData = %d", aiData[0], aiData[1], *ptr); return 0; } Output: 100, 200, 200 Explanation: In the above example, two operators are involved and both have different precedence. The precedence of post ++ is higher than the *, so first post ++ will be executed and above expression, *p++ will be equivalent to *(p++). In another word you can say that it is post-increment of address and output is 100, 200, 200. #include int main(void) { int aiData[5] = {100,200,300,400,500}; int *ptr = aiData; ++*ptr; printf("aiData[0] = %d, aiData[1] = %d, *ptr = %d", aiData[0], aiData[1], *ptr); return 0; } Output: 101 , 200 , 101 Explanation: In the above example, two operators are involved and both have the same precedence with a right to left associativity. So the above expression ++*p is equivalent to ++ (*p). In another word, we can say it is pre-increment of value and output is 101, 200, 101.

Related questions

0 votes
    Are the expressions *++ptr and ++*ptr same?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    Are the expressions *ptr ++ and ++*ptr same ?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    In tf.nn.max_pool of tensorflow what is the difference between 'SAME' and 'VALID'? I read in here that ... pool means in tensorflow? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    ‘ptr’ is a pointer to a data type. The expression *ptr++ is evaluated as?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    What will be the output of the program? #include #include void fun(char *msg, ); int main() { fun( indiabix , 1, 4, ... 7 11 0 1 4 7? Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Can you explain the difference between Data Warehousing and Business Intelligence?...
asked Feb 4, 2023 in Technology by JackTerrance
0 votes
    Explain the Difference Between Tableau Worksheet, Dashboard, Story, and Workbook?...
asked Mar 30, 2021 in Technology by JackTerrance
0 votes
    Explain the difference between SAP BASIS and SAP ABAP?...
asked Jan 5, 2021 in Technology by JackTerrance
0 votes
    Can you explain the difference between direct and alternating current?...
asked Dec 12, 2020 in Technology by JackTerrance
0 votes
    Explain the difference between traditional Waterfall model and Agile testing?...
asked Nov 26, 2020 in Technology by Editorial Staff
0 votes
    Explain the difference between role and profile in Salesforce?...
asked Nov 12, 2020 in Technology by JackTerrance
0 votes
    Explain the difference between atomic and nonatomic synthesized properties....
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Explain the difference between git fetch and git pull....
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    Explain the difference between a centralized and distributed version control system (VCS)....
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    Explain the difference between Swift vs Objective-C.?...
asked Nov 30, 2020 in Technology by JackTerrance
...