Hello guys, i'm new here, i want to learn c++. I worked for about 3 hours and i have a problem with scanf, can anyone explain to me?
source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main() {
int a = 5, b = 5;
printf("A value is: %d", a);
printf("\n A value location is: %d \nNew a value is: ", &a);
scanf_s("%d", a);
printf("New number is: %d", a);
return 0;
}
| |
Error code:
'c++ project.exe' (Win32): Loaded 'C:\Users\AlexPC\Desktop\c++ project\c++ project\x64\Debug\c++ project.exe'. Symbols loaded.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1d.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'.
'c++ project.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'.
The thread 0x1f78 has exited with code 0 (0x0).
Exception thrown at 0x00007FFE7370DDF6 (ucrtbased.dll) in c++ project.exe: 0xC0000005: Access violation writing location 0x0000000000000005.