Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The code you provided will not compile correctly because it is trying to assign an integer value to a pointer variable.

Here's the step by step explanation:

  1. int n = 98; This line declares an integer variable n and initializes it with the value 98.

  2. int *p = &n; This line declares a pointer to an integer p and assigns it the address of n. So, p is now pointing to n.

  3. p = 402; This line is trying to assign the integer value 402 to the pointer p. This is not allowed because p is a pointer and it should be assigned an address of a variable, not a direct integer value.

So, this code will result in a compilation error. If the code was corrected to *p = 402; then the value of n would be 402 because p is pointing to n and we are changing the value at the address p is pointing to.

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.