C Language Assignment Help
Way 1 : Assignment Operator used to Assign Value
int main() {
int value;
value = 55;
return (0);
}
In the abov e ex ampl e, w e hav e assigned 55 to a v ariabl e ‘v al ue’.
Way 2 : Assignment Operator used To Type Cast.
int value;
value = 55.450;
printf("%d",value);
Assignment operator can ty pe cast higher v al ues to l ow er v al ues. It can al so cast l ow er v al ues to higher v al ues
Way 3 : Assignment Operator in If Statement
if(value = 10)
printf("True");
else
printf("False");
It w ould be interesting tounderstand above program. Above Program will always execute True Condition because Assignment Operator is used inside if
statement not comparison operator. Lets see w hat w il l happen in abov e ex ampl e –
Constant number 10 will be assignedtovariable ‘value’. Variable ‘value’ will be treated as positive non-zero number, w hich is considered as true condition.
if(value = 0)
printf("True");
else
printf("False");
In bel ow case el se bl ock w il l be ex ecuted
Shorthand assignment operator
Shorthand assignment operator is used ex press the sy ntax that are al ready av ail abl e in shorter w ay
Operator symbol Name of the operator Example Equivalent construct
+= Addition assignment x += 4; x = x + 4;
-= Subtraction assignment x -= 4; x = x – 4;
*= Multiplication assignment x *= 4; x = x * 4;
/= Division assignment x /= 4; x = x / 4;
%= Remainder assignment x %= 4; x = x % 4;
Example : Shorthand assignment operator
#include<stdio.h>
int main() {
int res;
res = 11;
res += 4;
printf("nResult of Ex1 = %d", res);
res = 11;
res -= 4;
printf("nResult of Ex2 = %d", res);
res = 11;
res *= 4;
printf("nResult of Ex3 = %d", res);
res = 11;
res /= 4;
printf("nResult of Ex4 = %d", res);
res = 11;
res %= 4;
printf("nResult of Ex5 = %d", res);
return 0;
}
Output :
Result of Ex1 = 15
Result of Ex2 = 7
Result of Ex3 = 44
Result of Ex4 = 2
Result of Ex5 = 3

C language assignment help

  • 1.
    C Language AssignmentHelp Way 1 : Assignment Operator used to Assign Value int main() { int value; value = 55; return (0); } In the abov e ex ampl e, w e hav e assigned 55 to a v ariabl e ‘v al ue’. Way 2 : Assignment Operator used To Type Cast. int value; value = 55.450; printf("%d",value); Assignment operator can ty pe cast higher v al ues to l ow er v al ues. It can al so cast l ow er v al ues to higher v al ues Way 3 : Assignment Operator in If Statement if(value = 10) printf("True"); else printf("False");
  • 2.
    It w ouldbe interesting tounderstand above program. Above Program will always execute True Condition because Assignment Operator is used inside if statement not comparison operator. Lets see w hat w il l happen in abov e ex ampl e – Constant number 10 will be assignedtovariable ‘value’. Variable ‘value’ will be treated as positive non-zero number, w hich is considered as true condition. if(value = 0) printf("True"); else printf("False"); In bel ow case el se bl ock w il l be ex ecuted Shorthand assignment operator Shorthand assignment operator is used ex press the sy ntax that are al ready av ail abl e in shorter w ay Operator symbol Name of the operator Example Equivalent construct += Addition assignment x += 4; x = x + 4; -= Subtraction assignment x -= 4; x = x – 4; *= Multiplication assignment x *= 4; x = x * 4; /= Division assignment x /= 4; x = x / 4; %= Remainder assignment x %= 4; x = x % 4; Example : Shorthand assignment operator #include<stdio.h> int main() { int res; res = 11; res += 4; printf("nResult of Ex1 = %d", res); res = 11; res -= 4; printf("nResult of Ex2 = %d", res); res = 11; res *= 4; printf("nResult of Ex3 = %d", res); res = 11; res /= 4; printf("nResult of Ex4 = %d", res); res = 11;
  • 3.
    res %= 4; printf("nResultof Ex5 = %d", res); return 0; } Output : Result of Ex1 = 15 Result of Ex2 = 7 Result of Ex3 = 44 Result of Ex4 = 2 Result of Ex5 = 3