I'm a very very beginner to C programming language I wonder that there's a problem with my IDE or I can't figure what. The problem is when a write some codes and compile them it runs great but suddenly stops working. This is for every program and every IDE and even tested this on two of my computers but both did the same problem.
For example the most simplest code crashes, like:
#include <stdio.h>
#include <conio.h>
int main(){
int num1, num2, result;
result = num1 + num2;
printf("Enter Value 1:\n");
scanf("%d",num1);
printf("\nEnter Value 2:");
scanf("%d",num2);
printf("The result of %d + %d is %d",num1,num2,result);
getch();
return 0;
}
And when I run it on CodeBlocks or DevCPP or compile it with MinGW or VC++ compiler it crashes after entering the data at scanf to the program. And by the way my compiler and IDE is installed and configured correctly and with no problems. But IDK all of my compiled programs keeps crashing! Even a simple HELLO WORLD prorgam! Please help me. My first PC: INTEL Pentium D 3.4 GhZ 4GB RAM DDR3 Windows 8.1 Pro x64
My second PC: Intel Atom 1.4 GhZ 2GB RAM Windows 8.1 Pro x86
And I turned off my AV to make sure it's not the problem from AV but same problem again. Crash.
Error information: Problem Event Name: APPCRASH Application Name: Arithmetic Operations.exe Application Version: 0.0.0.0 Application Timestamp: 57a9fa0c Fault Module Name: msvcrt.dll Fault Module Version: 7.0.9600.16384 Fault Module Timestamp: 5215f944 Exception Code: c0000005 Exception Offset: 000000000001dd5c OS Version: 6.3.9600.2.0.0.256.48 Locale ID: 1065 Additional Information 1: 3d05 Additional Information 2: 3d052cae4082fb501044f19c5df730a9 Additional Information 3: 4191 Additional Information 4: 41915c3946c3709cfe888641ded802fc
Please help me!
scanf()
must be a pointers:scanf("%d",&num1); scanf("%d",&num2);
– Sergio Aug 9 '16 at 15:47result = num1 + num2;
move to after inputnum1
andnum2
. – BLUEPIXY Aug 9 '16 at 15:48result = num1 + num2;
is undefined behavior as you never initialized the variables. – NathanOliver Aug 9 '16 at 15:49C / C++
is undefined as the expression is unsequenced. – Bathsheba Aug 9 '16 at 15:51result = num1 + num2
is undefined behavior here, it's also broken logic: you're first computing the sum and then actually getting the information about the numbers to sum. You first drink water and only then pour it into your glass. – ForceBru Aug 9 '16 at 15:52