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 be the output of the following code?int main() {    int a = 10;    int *p = &a;    *p = 20;    printf("%d\n", a);    return 0;}

In the below code -For what value of n does the program print 21 ?

What is the size of *p in this code?int **p;

What is the output for the following code?123456789101112131415#include <stdio.h> int main() { int n = 5; int arr[5] = {1, 2, 3, 4, 5}; int e = 0; for (int i = 0; i < n; ++i) { if (arr[i] % 2 == 0) { ++e; } } double p = (double)e / n * 100; printf("%.2f", p); return 0;}

What will be the output of the following code?1234567891011121314151617#include <stdio.h>int main() { int a = 100; int *p = &a; int count = 0; while (count < 1) { *p += 1; ++count; } int b = *p; printf("%d, %d", a, b); return 0; }

1/3

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.