#include <stdio.h>
int *check();
int main()
{
int *c;
c = check();
printf("%d\n", c);
return 0;
}
int *check()
{
int i=10; int *p=&i;
return p;
}
Vinod Supnekar
0
Newbie Poster
Recommended Answers
Jump to PostThe code has undefined behavior because check() is returning a pointer to an object that doesn't exist after check() returns to it's caller. That is illegal in C and C++.
Jump to Postyes -- printf() will attempt to use it.
All 8 Replies
sepp2k
378
Practically a Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
sepp2k
378
Practically a Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
sepp2k
378
Practically a Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
sepp2k
378
Practically a Master Poster
Gonbe
32
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.