News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

C::B .exe file crashes when I put a pointer in the source file

Started by tomsonjack, November 19, 2017, 04:03:38 AM

Previous topic - Next topic

tomsonjack

Hi guys, when I put a pointer in my source code, the code can be compiled, and the .exe file also can be generated.
But the .exe can't be executed properly, and it just crushed on the Windows 7.

The followed is the software version.
C::B version:13.12
SDK version:1.19.0
wx version: 2.8.12
MinGW version: 4.7.1

The source code is:

#include <stdio.h>

void main()
{   int a, *p;
    a=2;
    *p=a;
    printf("a=%d",a);
}

Could you please help me with this issue?

stahta01

Find a site that teaches programming. Edit2: Your code is likely trying to write to address zero which is undefined.
Edit: Or a site that supports your compiler. They will likely want a build log http://forums.next.codeblocks.org/index.php/topic,9996.0.html

Please read the rules before you post again on this site
http://forums.next.codeblocks.org/index.php/topic,9996.0.html
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

sodev

Dereferencing an uninitialized pointer is undefined behavior, most probably you wanted to do p = &a;, but still there is no sense in this.

But indeed here is no compiler problem and for sure no CodeBlocks problem, only a user doesnt know c basics problem :). No need for a build log because this is syntactically correct and builds fine.

tomsonjack

Hi guys, Thanks a lot.  An uninitialized pointer is root cause. This is a C basics knowledge, which I should konw.