strange output in c program
Marko Turk
markoml at markoturk.info
Wed Jul 8 11:41:54 UTC 2020
On Wed, Jul 08, 2020 at 05:04:26PM +0530, rahul deshmukh wrote:
> Hi Team,
> i was learning c programming and came across a very strange output. kindly
> someone please guide me if i am missing anything.
>
> rdx at FreeBSD:~/Projects/Clang/chapter3 % uname -a
> FreeBSD FreeBSD 12.1-RELEASE FreeBSD 12.1-RELEASE r354233 GENERIC amd64
> ========================================================================
> rdx at FreeBSD:~/Projects/Clang/chapter3 % cat example6.c
> #include <stdio.h>
> int main()
> {
> int a = 300, b, c;
> if(a >= 400)
> {
> printf("shouldn't print\n");
> b = 300;
> }
> c=200;
> printf("%d %d\n", b, c);
> return 0;
> }
> =========================================================
> rdx at FreeBSD:~/Projects/Clang/chapter3 % make example6
> `example6' is up to date.
> rdx at FreeBSD:~/Projects/Clang/chapter3 % ./example6
> 300 200==> should be garbage value instead of 300?
The behaviour is undefined so anything can happen. Even different
optimization flags can change the value printed.
BR/Marko
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20200708/15265d3d/attachment.sig>
More information about the freebsd-hackers
mailing list