328 views
1 1 vote
I am getting 18 as answer. Isn't this a case of Dangling pointer? How can i get 18 since p is pointing to something that dose not exist?

#include <stdio.h>
int *func(int, int);
int main()
{
    int i = 3, f = 6, *p;
    p = func(i, f);
    printf("%d\n", *p);
    return 0;
}
int *func(int i, int f)
{
    int x;
    x = i*f;
    return(&x);
}

Please log in or register to answer this question.

Position:
Show:

Related questions

8 8 votes
1 1 answer
264
264 views
GO Classes asked Jun 19
264 views
What is the output of the following code?#include <stdio.h void fun(int a[], int *p) { a = a + 5; *(p + 2) = *(p + 2) + 10; p++; *p = *p + 1; } int main() { int arr[] =...
6 6 votes
1 1 answer
215
215 views
GO Classes asked Jun 19
215 views
What is the output of the following code?#include <stdio.h int main() { int arr[] = {10, 20, 30}; int *p = arr; printf("%d %d", *p, *(arr + 2)); return 0; }$\texttt{10 20...
7 7 votes
1 1 answer
223
223 views
GO Classes asked Jun 6
223 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...
7 7 votes
1 1 answer
229
229 views
GO Classes asked Jun 6
229 views
What is the output of the following code?#include <stdio.h int main() { int a = 8, b = 12; int *p = &a; int *q = &b; *p = *p + *q; q = p; *q = *q - 5; printf("%d %d", a, ...