0

Here is what i get

#include<stdlib.h>
#include<stdio.h>
int main()
{
    char v1=0;
    char v2=0;
    printf("Enter the number of elements of first vectors : ");
    scanf(" %d",&v1);
    printf("v1=%d\n",v1);
    printf("Enter the number of elements of second vectors : ");
    scanf(" %d",&v2);
    printf("v2=%d\n",v2);
    printf("v1=%d\n",v1);
    printf("v2=%d\n",v2);
    return 0;
}

If we assumed v1=50 and v2=300 Why does v1 value changes in the second print

Optix
  • 1
  • 1

1 Answers1

1

here is what my compiler says with warning turned up max

warning C4477: 'scanf' : format string '%d' requires an argument of type 'int *', but variadic argument 1 has type 'char *'

you need

scanf(" %c",&v1);
pm100
  • 48,078
  • 23
  • 82
  • 145