i am just starting coding in vc++ 2010 express
i am tring for a simple scanf program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* scanf example */
#include <stdio.h>
#include "conio.h"
int main ()
{
int a;
int i;
int ans;
printf ("1 NUM ");
scanf ("%d",a);
printf ("2nd");
scanf ("%d",&i);
ans=a*i;
printf("* is %d",ans);
return 0;
_getch();
}
it gives message success=1
but after some time when i play
Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.
and when i say to continue it continues and
Unhandled exception at 0x5ab1e30e (msvcr100d.dll) in scanf.exe: 0xC0000005: Access violation writing location 0xcccccccc.
i want to ask what wrong i am doing and when this Unhandled exception comes?
That's because you passed an integer instead of a pointer to an integer in the first scanf call.
And you just demonstrated why you should not use scanf/printf/etc. in C++. They're not type-safe.
hey thanks Athar i tried many programs using that all worked perfectly
i tried with 3 num other signs and much..................... THANKS TOOOOOOOOOO MUCH
You have an error in line 4, (must be int main()) and another one in line 10 (must be endl, not end1).
Another problem is that you're using squareroot uninitialized in line 9. That's not even close to how you calculate a square root anyway. Just use sqrt: http://www.cplusplus.com/reference/clibrary/cmath/sqrt/
/* scanf example */
#include <stdio.h>
#include "conio.h"
int main ()
{
int a;
int i;
int ans;
printf ("1 NUM ");
scanf ("%d",a);-------------------> i think error on this line... scanf("%d", &a) might be the right
printf ("2nd");
scanf ("%d",&i);
ans=a*i;
printf("* is %d",ans);
return 0;
_getch();
}
/* scanf example */
#include <stdio.h>
#include "conio.h"
int main ()
{
int a;
int i;
int ans;
printf ("1 NUM ");
scanf ("%d",a);-------------------> i think error on this line... scanf("%d", &a) might be the right
printf ("2nd");
scanf ("%d",&i);
ans=a*i;
printf("* is %d",ans);
_getch();
return 0;