Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what happen to the Variable C?

–2 votes
asked Apr 12, 2018 by Power Murugan (190 points)
#include<stdio.h>
main()
{
    int a,b,c;
    printf("Enter two values\n");
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    c=a+b;
    printf("the addition of %d and %d is %d",a,b,c);
}

i have given a=2;b=2;c=3;

the result is the addition of 2 and 2 is 4; but the value of c is declared by mine; but have given input value of c by knownly to check the response; but no where considered in equation and no error is coming why?

2 Answers

0 votes
answered Apr 12, 2018 by shipof123 (260 points)

it is unclear what you are asking, but if you are wondering why c is equal to 4 it is because you declared it to be the value of a+b, which makes the scanf("%d",&c); line completely useless if I say 

int c=5;//initiates c with the value of 5

c=6;//changes that value to 6

printf("%d",c);

output:

6

so when you say

scanf("%d",&c);//is whatever the user inputs
    c=a+b;//is no longer user input, but instead a+b

you are overidding the initial assignment

0 votes
answered Apr 15, 2018 by SUBASH S (150 points)
why y have given the value to c?

because the value given to the variable to c is given error.........................but the last condition given to c is then changed to 4.....................                   .
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...