Knowee
Questions
Features
Study Tools

What is the value of n after the following code is executed?int n = 98;int *p = &n;*p++;

Question

What is the value of n after the following code is executed?

int n = 98;
int *p = &n;
*p++;
🧐 Not the exact question you are looking for?Go ask a question

Solution

The code you provided is incorrect and will not compile. The line "*p++;" is trying to increment the value of the pointer 'p', not the value 'n' that 'p' points to. If you want to increment the value of 'n' using the pointer 'p', you should use "(*p)++;" instead.

However, if the code was "*p++;", it would not change the value of 'n'. It would instead increment the memory address that 'p' is pointing to, which is not what you want.

So, if you correct the code to:

int n = 98;
int *p = &n;
(*p)++;

The value of 'n' after the code is executed would be 99.

This problem has been solved

Similar Questions

What will the result of num variable after execution of the following statements? int num = 58; num % = 11; the given code is in c

What is the output of the following code?int arr[] = {1, 2, 3, 4, 5};int *p = arr;p++;printf("%d\n", *p);

How many times is the comparison i >= n performed in the following program?int i = 300, n = 150;main(){ while (i >= n){ i = i-2; n = n+1; }}

write a program to print integer no, from 1 to n where n is the input from the user using do while loop in c language use getch

What will you see on the terminal?int main(void){ int *ptr; *ptr = 98; printf("%d\n", *ptr); return (0);}It doesn’t compileSegmentation Fault980

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.