Consider the following code.
#include<stdio.h> int *abc(); // this function returns a pointer of type int int main() { int *ptr; ptr = abc(); printf("%d", *ptr); return 0; } int *abc() { int i = 45500, *p; p = &i; return p; }
Conclusion:
45500
I know, according to the link , this type of behavior is undefined. But why do I get the correct value every time I run the program.
, abc, "" , . , , , . . , , , , . , , . . , .
abc
. , C , .
, undefined , undefined. UB ( , UB).
, , , , , , , , .
Source: https://habr.com/ru/post/1653924/More articles:Understanding and creating Xcode XML layouts - xmlPandas, dataframe with datetime64 column, query by clock - pythonUsing the created Swagger TypeScript Rest Client in Angular2 - javascripthow can it return a type instead of an object, be valid, not understanding the code fragment - c ++What is the encoding of the body of a Gmail message? How to decode it? - pythonHow to get the sum of total values ββin stackedBar ChartJs - djangoClear all Sitecore profile data - sitecoreTemplate argument for function type in C ++ - c ++JS / Jquery diagram that allows HTML tags in its label? - javascriptDelete comments from file and save integers - c ++All Articles