in Technology by
What is Indirection and Increment/Decrement operators with a pointer in C?

1 Answer

0 votes
by
We can combine the indirection operator (*) with increment/decrement (++ , — )operators. Let’s see some example C codes to understand the behavior of the indirection and increment/decrement operators. Indirection operator with pre-increment operator: #include int main(void) { int aiData[5] = {100,200,300,400,500}; int *piData = aiData; ++*piData; printf("aiData[0] = %d, aiData[1] = %d, *piData = %d", aiData[0], aiData[1], *piData); 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. #include int main(void) { int aiData[5] = {100,200,30,40,50}; int *piData = aiData; *++piData; printf("aiData[0] = %d, aiData[1] = %d, *piData = %d", aiData[0], aiData[1], *piData); return 0; } Output: 100, 200, 200 Explanation: In the above example, two operators are involved and both have the same precedence with the right to left associativity. So the above expression *++p is equivalent to *(++p). In another word you can say it is pre-increment of address and output is 100, 200,200.

Related questions

0 votes
    What is the process to create increment and decrement statement in C?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
0 votes
    How is a Program increment a pointer in C?...
asked Jan 24, 2021 in Technology by JackTerrance
+1 vote
    What is indirection in C-programming?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
+1 vote
    How many operators are there under the category of ternary operators in C Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    a. State the number of bytes occupied by char and int data types. b. Differentiate between = and == ... implicit type conversion. Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
0 votes
    a. State the number of bytes occupied by char and int data types. b. Differentiate between = and == ... implicit type conversion. Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    a. State the number of bytes occupied by char and int data types. b. Differentiate between = and == ... implicit type conversion. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    A manufacturer has three machine operators A, B and C. The first operator A produces 1% defective items, where as ... produced by A? Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    How many relational operators are used in C? ( Answer in one word ) Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    What is Indirection or Dereference Operator ( * )?...
asked Jan 22, 2021 in Technology by JackTerrance
...