IncludeHelp_logo

  • Data Structure
  • Coding Problems
  • C Interview Programs
  • C++ Aptitude
  • Java Aptitude
  • C# Aptitude
  • PHP Aptitude
  • Linux Aptitude
  • DBMS Aptitude
  • Networking Aptitude
  • AI Aptitude
  • MIS Executive
  • Web Technologie MCQs
  • CS Subjects MCQs
  • Databases MCQs
  • Programming MCQs
  • Testing Software MCQs
  • Digital Mktg Subjects MCQs
  • Cloud Computing S/W MCQs
  • Engineering Subjects MCQs
  • Commerce MCQs
  • More MCQs...
  • Machine Learning/AI
  • Operating System
  • Computer Network
  • Software Engineering
  • Discrete Mathematics
  • Digital Electronics
  • Data Mining
  • Embedded Systems
  • Cryptography
  • CS Fundamental
  • More Tutorials...
  • Tech Articles
  • Code Examples
  • Programmer's Calculator
  • XML Sitemap Generator
  • Tools & Generators

IncludeHelp

  • C - Getting Started
  • C - Overview
  • C - Advantages & Disadvantages
  • C - Character Set
  • Gcc Vs. G++
  • Why We should Use C?
  • C - Basic Rules
  • C - Comments
  • C - Variable Naming Conventions
  • C - Variable Initialization
  • C - Constants
  • C - Character Constant
  • C - Octal Literals
  • C - Hexadecimal Literals
  • C - Automatic (auto) Variables
  • Local Vs. Global Variables
  • C - Access Global Variables
  • Is exit() & return Statements are Same?
  • C - Print Float Value
  • C - Print Multiple Lines Using printf()
  • C - Argument Index Specification
  • C - Value Returned by scanf()
  • C - Returned Values of printf() & scanf()
  • What do 'lvalue' & 'rvalue' Mean
  • Automatic (auto) Vs. Static Variables

C Data Types

  • C - Data Types & Operators
  • C - Basic Data Types
  • C - 'unsigned char' For Memory Optimization
  • short Vs. short int Vs. int
  • unsigned int Vs. size_t
  • C - Storage Classes Introduction
  • C - Storage Classes With Examples
  • C- Type Conversion
  • C - Type Qualifiers

C Input/Output

  • C - Read String With Spaces
  • C - Input String of Unknown Length
  • C - Disadvantages of scanf()
  • C - scanf() need '%lf' for doubles, when printf() is okay with just '%f'
  • C - Format Specifier for unsigned short int
  • C - printf() Format Specifier for bool
  • C - printf() Arguments for long
  • C - printf() Specifier for double
  • Is there a printf() converter to print in binary format?
  • C - Nested printf()
  • printf() Vs. puts()
  • printf() Vs. sprintf()
  • %d Vs. %i format Specifiers
  • C - Single Character Input & Output
  • C- Formatted Input & Output
  • C - Octal & Hex Escape Sequences
  • C - Convert Float to String
  • gets() Vs. fgets()
  • C - Input Unsigned Integer Value
  • C - Input Octal Value
  • C - Input Hex Value
  • C - Input Decimal, Octal & Hex in char Variables
  • C - Input With '%i'
  • C - Input Individual Characters
  • C - Skip characters While Reading Integers
  • C - Read Memory Address
  • C - Printing Variable's Address
  • C - printf() Examples & Variations

C Operators

  • C - Operators Precedence & Associativity
  • Operators Vs. Operands
  • C - Unary Operators
  • C - Equality Operators
  • C - Logical AND (&&) Operator
  • C - Logical OR (||) Operator
  • C - Logical NOT (!) Operator
  • C - Modulus on Negative Numbers
  • C - Expression a=b=c (Multiple Assignment) Evaluates
  • C - Expression a==b==c (Multiple Comparison) Evaluates
  • C - Complex Return Statement Using Comma Operator
  • C - Comma Operator
  • C - Bitwise Operators
  • C - Bitwise One's Compliment
  • C - Modulus of Float or Double Numbers

C Conditional Statements

  • C - If Else Statements
  • C - Switch Case
  • C - Switch Statements Features, Disadvantages
  • C - Using Range With Switch

C Control Statements

  • C - 'goto' Statement
  • C - break & continue
  • Print Numbers From 1 to N Using goto
  • C - Looping
  • C - Looping Programs
  • C - Nested Loops
  • C - Entry Controlled Vs. Exit Controlled Loops
  • C - Sentinel Vs. Counter Controlled Loops
  • C - Use for Loop as Infinite Loop
  • C - Strings in C language programming
  • C - string.h Functions
  • C - memcpy() Function
  • C - Write Your Own memcpy()
  • C - memset() Function
  • C - Write Your Own memset()

C Functions

  • C - Library & User-define Functions
  • C - Static Functions
  • C - Scope of Function Parameters
  • C - Recursion
  • C - Recursion Examples
  • More on Arrays
  • C - Properties/Characteristics of Array

C Structure and Unions

  • C Structures
  • C - Initialize a Structure in Accordance
  • C - Size of Structure With No Members
  • C -Pointer to Structure
  • C - Nested Structure Initialization
  • C - Nested Structure With Examples
  • C - Size of Structure
  • C - Copy Complete Structure in Byte Array
  • C - Pointer to Union
  • C - Pointers
  • C - Pointer Rules
  • C - Pointers Declarations
  • C - Pointer Address Operators
  • C - Accessing Variable Using Pointer
  • C - Address of (&) & Dereference (*) Operators
  • C - NULL Pointer
  • C - Pointers as Argument
  • C - Pointer Arithmetic
  • C - Pointer to an Array
  • C - Evaluation of Statement '*ptr++'
  • C - Pointer & Non-pointer Variables Declarations Together
  • C - Pointer to an Array of Integers
  • C - Pointer to Pointer
  • C - void Pointer as Function Argument
  • char s[] Vs. char *s
  • C - Copying Integer Value to Char Buffer & Vice Versa
  • C - Call by Reference Vs. Call by Value
  • C - Typedef Function Pointer

C Preprocessor Directives

  • Recommendation for defining a macro in C language
  • Macro expansion directives (#define, #undef) in C language
  • Complex macro with arguments (function like macro) in C language
  • C language #ifdef, #else, #endif Pre-processor with Example
  • C language #if, #elif, #else, #endif Pre-processor with Example
  • Parameterized Macro - we cannot use space after the Macro Name
  • Stringizing Operator (#) in C
  • Token Pasting Directive Operator (##) in C

C Command-line Arguments

  • C language Command Line Arguments

C File Handlings

  • C - Basics of File Handling
  • C - File Handling Programs
  • C - Graphics Modes
  • C - Using Colors in Text Mode
  • C - More on Graphics Modes
  • C - OUTTEXTXY() & SETTEXTSTYLE() Functions
  • C - Draw Circle & Rectangle
  • C - graphics.h Functions
  • C - More Graphics-related Interesting Functions

C Advance Topics

  • C - Process Identification (pid_t)
  • C - getpid() & getppid()
  • C - Rrules For Writing C/C++ Program
  • C - Tips For Embedded Development
  • C - Optimization Techniques
  • C Vs. Embedded C
  • C- File Management System Calls
  • C/C++ Multithreading
  • C/C++ - Sum of Array Using Multithreading

C Tips and Tricks

  • C - Copy Two Bytes Int. to Byte Buffer
  • C - Is Pre-increment Faster than Post-increment?
  • C - Create Delay Function
  • Why should We use 'f' With Float Literal in C?
  • C - Replacing a Part of String
  • C- Comparing Number of Characters of Two Strings
  • C - Safest Way to Check Value Using ==
  • C- Check EVEN or ODD W/O % Operator
  • C- Use Single Byte to Store 8 Values
  • C- Funny Trick to Use C++ in C
  • C - Trick to Print Maximum Value of an unsigned int
  • C - Print Maximum Value of an unsigned int using One's Compliment (~) Operator in C
  • Why we should use switch instead of if else?
  • How to initialize array elements with hexadecimal values in C?
  • How should we declare/define a pointer variable?

C Important Topics

  • C - Working With Hexadecimal
  • C - Working With octal
  • C - Convert ASCII String (char[]) to BYTE Array
  • C - Convert ASCII String (char[]) to Octal String
  • C - Convert ASCII String (char[]) to Hex String
  • C - Assign Binary Calue in a Variable Directly
  • C - Check Particular Bit is SET or Not
  • C- Set, Clear, & Toggle a Bit
  • C - Value of 'EOF'
  • C - Print printf("Hello world."); Using printf()
  • C - Print Text in New Line w/O Using '\n'
  • C - Return 0 From int main()
  • 'Super Loop' Architecture for Embedded C
  • C - Executing System Commands
  • C - Infix To Postfix Conversion Using Stack
  • C - Evaluation of Postfix Expressions Using Stack
  • C - Polynomial Addition Using Structure
  • C - conio.h Functions
  • SQLite with C language
  • C - SQL Table Creation, Insertion
  • C - Aptitude Questions
  • C - Interview Questions
  • C - Find Output Programs

Advertisement

Home » C programming language

How expression a=b=c (Multiple Assignment) evaluates in C programming?

Since C language does not support chaining assignment like a=b=c ; each assignment operator ( = ) operates on two operands only. Then how expression a=b=c evaluates?

According to operators associativity assignment operator ( = ) operates from right to left, that means associativity of assignment operator ( = ) is right to left.

Expression a=b=c is actually a=(b=c) , see how expression a=(b=c) evaluates?

  • Value of variable c will be assigned into variable b first.
  • Then value of variable b will be assigned into variable a .

Finally value of variables a and b will be same as the value of variable c .

Consider the following program

Assigning a value to multiple variables of same type

By using such kind of expression we can easily assign a value to multiple variables of same data type, for example - if we want to assign 0 to integer variables a , b , c and d ; we can do it by following expression:

Related Tutorials

  • Precedence and associativity of Arithmetic Operators
  • Difference b/w operators and operands in C
  • Unary Operators in C with Examples
  • Equality Operators in C,C++
  • Logical AND (&&) operator with example
  • Logical OR (||) operator with example
  • Logical NOT (!) operator with example
  • Modulus on negative numbers in C language
  • How expression a==b==c (Multiple Comparison) evaluates in C programming?
  • Complex return statement using comma operator in c programming language
  • Explain comma operator with an example
  • Bitwise Operators and their working
  • Bitwise One's Compliment (Bitwise NOT Operator) in C
  • Modulus of two float or double numbers in C language
  • Switch Case Tutorial, Syntax, Examples and Rules in C language
  • Switch Statements (features, disadvantages and difference with if else)
  • Using range with switch case statement
  • 'goto' Statement in C language
  • Use of break and continue within the loop in c
  • Print numbers from 1 to N using goto statement
  • Looping Tutorial in C programming
  • Nested Loops in C programming language
  • How to use for loop as infinite loop in C?

Comments and Discussions!

Load comments ↻

  • Marketing MCQs
  • Blockchain MCQs
  • Artificial Intelligence MCQs
  • Data Analytics & Visualization MCQs
  • Python MCQs
  • C++ Programs
  • Python Programs
  • Java Programs
  • D.S. Programs
  • Golang Programs
  • C# Programs
  • JavaScript Examples
  • jQuery Examples
  • CSS Examples
  • C++ Tutorial
  • Python Tutorial
  • ML/AI Tutorial
  • MIS Tutorial
  • Software Engineering Tutorial
  • Scala Tutorial
  • Privacy policy
  • Certificates
  • Content Writers of the Month

Copyright © 2024 www.includehelp.com. All rights reserved.

cppreference.com

Assignment operators.

(C11)
Miscellaneous
General
(C11)
(C99)

Assignment and compound assignment operators are binary operators that modify the variable to their left using the value to their right.

Operator Operator name Example Description Equivalent of
= basic assignment a = b becomes equal to
+= addition assignment a += b becomes equal to the addition of and a = a + b
-= subtraction assignment a -= b becomes equal to the subtraction of from a = a - b
*= multiplication assignment a *= b becomes equal to the product of and a = a * b
/= division assignment a /= b becomes equal to the division of by a = a / b
%= modulo assignment a %= b becomes equal to the remainder of divided by a = a % b
&= bitwise AND assignment a &= b becomes equal to the bitwise AND of and a = a & b
|= bitwise OR assignment a |= b becomes equal to the bitwise OR of and a = a | b
^= bitwise XOR assignment a ^= b becomes equal to the bitwise XOR of and a = a ^ b
<<= bitwise left shift assignment a <<= b becomes equal to left shifted by a = a << b
>>= bitwise right shift assignment a >>= b becomes equal to right shifted by a = a >> b
Simple assignment Notes Compound assignment References See Also See also

[ edit ] Simple assignment

The simple assignment operator expressions have the form

lhs rhs
lhs - expression of any complete object type
rhs - expression of any type to lhs or with lhs

Assignment performs implicit conversion from the value of rhs to the type of lhs and then replaces the value in the object designated by lhs with the converted value of rhs .

Assignment also returns the same value as what was stored in lhs (so that expressions such as a = b = c are possible). The value category of the assignment operator is non-lvalue (so that expressions such as ( a = b ) = c are invalid).

rhs and lhs must satisfy one of the following:

  • both lhs and rhs have compatible struct or union type, or..
  • rhs must be implicitly convertible to lhs , which implies
  • both lhs and rhs have arithmetic types , in which case lhs may be volatile -qualified or atomic (since C11)
  • both lhs and rhs have pointer to compatible (ignoring qualifiers) types, or one of the pointers is a pointer to void, and the conversion would not add qualifiers to the pointed-to type. lhs may be volatile or restrict (since C99) -qualified or atomic (since C11) .
  • lhs is a (possibly qualified or atomic (since C11) ) pointer and rhs is a null pointer constant such as NULL or a nullptr_t value (since C23)
has type (possibly qualified or atomic(since C11)) _Bool and rhs is a pointer or a value(since C23) (since C99)
has type (possibly qualified or atomic) and rhs has type (since C23)

[ edit ] Notes

If rhs and lhs overlap in memory (e.g. they are members of the same union), the behavior is undefined unless the overlap is exact and the types are compatible .

Although arrays are not assignable, an array wrapped in a struct is assignable to another object of the same (or compatible) struct type.

The side effect of updating lhs is sequenced after the value computations, but not the side effects of lhs and rhs themselves and the evaluations of the operands are, as usual, unsequenced relative to each other (so the expressions such as i = ++ i ; are undefined)

Assignment strips extra range and precision from floating-point expressions (see FLT_EVAL_METHOD ).

In C++, assignment operators are lvalue expressions, not so in C.

[ edit ] Compound assignment

The compound assignment operator expressions have the form

lhs op rhs
op - one of *=, /= %=, += -=, <<=, >>=, &=, ^=, |=
lhs, rhs - expressions with (where lhs may be qualified or atomic), except when op is += or -=, which also accept pointer types with the same restrictions as + and -

The expression lhs @= rhs is exactly the same as lhs = lhs @ ( rhs ) , except that lhs is evaluated only once.

If lhs has type, the operation behaves as a single atomic read-modify-write operation with memory order .

For integer atomic types, the compound assignment @= is equivalent to:

addr = &lhs; T2 val = rhs; T1 old = *addr; T1 new; do { new = old @ val } while (! (addr, &old, new);
(since C11)

[ edit ] References

  • C17 standard (ISO/IEC 9899:2018):
  • 6.5.16 Assignment operators (p: 72-73)
  • C11 standard (ISO/IEC 9899:2011):
  • 6.5.16 Assignment operators (p: 101-104)
  • C99 standard (ISO/IEC 9899:1999):
  • 6.5.16 Assignment operators (p: 91-93)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 3.3.16 Assignment operators

[ edit ] See Also

Operator precedence

Common operators

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b

a[b]
*a
&a
a->b
a.b

a(...)
a, b
(type) a
a ? b : c
sizeof


_Alignof
(since C11)

[ edit ] See also

for Assignment operators
  • Recent changes
  • Offline version
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
  • Page information
  • In other languages
  • This page was last modified on 19 August 2022, at 09:36.
  • Privacy policy
  • About cppreference.com
  • Disclaimers

Powered by MediaWiki

CProgramming Tutorial

  • C Programming Tutorial
  • Basics of C
  • C - Overview
  • C - Features
  • C - History
  • C - Environment Setup
  • C - Program Structure
  • C - Hello World
  • C - Compilation Process
  • C - Comments
  • C - Keywords
  • C - Identifiers
  • C - User Input
  • C - Basic Syntax
  • C - Data Types
  • C - Variables
  • C - Integer Promotions
  • C - Type Conversion
  • C - Type Casting
  • C - Booleans
  • Constants and Literals in C
  • C - Constants
  • C - Literals
  • C - Escape sequences
  • C - Format Specifiers
  • Operators in C
  • C - Operators
  • C - Arithmetic Operators
  • C - Relational Operators
  • C - Logical Operators
  • C - Bitwise Operators
  • C - Assignment Operators
  • C - Unary Operators
  • C - Increment and Decrement Operators
  • C - Ternary Operator
  • C - sizeof Operator
  • C - Operator Precedence
  • C - Misc Operators
  • Decision Making in C
  • C - Decision Making
  • C - if statement
  • C - if...else statement
  • C - nested if statements
  • C - switch statement
  • C - nested switch statements
  • C - While loop
  • C - For loop
  • C - Do...while loop
  • C - Nested loop
  • C - Infinite loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement
  • Functions in C
  • C - Functions
  • C - Main Function
  • C - Function call by Value
  • C - Function call by reference
  • C - Nested Functions
  • C - Variadic Functions
  • C - User-Defined Functions
  • C - Callback Function
  • C - Return Statement
  • C - Recursion
  • Scope Rules in C
  • C - Scope Rules
  • C - Static Variables
  • C - Global Variables
  • Arrays in C
  • C - Properties of Array
  • C - Multi-Dimensional Arrays
  • C - Passing Arrays to Function
  • C - Return Array from Function
  • C - Variable Length Arrays
  • Pointers in C
  • C - Pointers
  • C - Pointers and Arrays
  • C - Applications of Pointers
  • C - Pointer Arithmetics
  • C - Array of Pointers
  • C - Pointer to Pointer
  • C - Passing Pointers to Functions
  • C - Return Pointer from Functions
  • C - Function Pointers
  • C - Pointer to an Array
  • C - Pointers to Structures
  • C - Chain of Pointers
  • C - Pointer vs Array
  • C - Character Pointers and Functions
  • C - NULL Pointer
  • C - void Pointer
  • C - Dangling Pointers
  • C - Dereference Pointer
  • C - Near, Far and Huge Pointers
  • C - Initialization of Pointer Arrays
  • C - Pointers vs. Multi-dimensional Arrays
  • Strings in C
  • C - Strings
  • C - Array of Strings
  • C - Special Characters
  • C Structures and Unions
  • C - Structures
  • C - Structures and Functions
  • C - Arrays of Structures
  • C - Self-Referential Structures
  • C - Lookup Tables
  • C - Dot (.) Operator
  • C - Enumeration (or enum)
  • C - Structure Padding and Packing
  • C - Nested Structures
  • C - Anonymous Structure and Union
  • C - Bit Fields
  • C - Typedef
  • File Handling in C
  • C - Input & Output
  • C - File I/O (File Handling)
  • C Preprocessors
  • C - Preprocessors
  • C - Pragmas
  • C - Preprocessor Operators
  • C - Header Files
  • Memory Management in C
  • C - Memory Management
  • C - Memory Address
  • C - Storage Classes
  • Miscellaneous Topics
  • C - Error Handling
  • C - Variable Arguments
  • C - Command Execution
  • C - Math Functions
  • C - Static Keyword
  • C - Random Number Generation
  • C - Command Line Arguments
  • C Programming Resources
  • C - Questions & Answers
  • C - Quick Guide
  • C - Cheat Sheet
  • C - Useful Resources
  • C - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

Assignment Operators in C

In C language, the assignment operator stores a certain value in an already declared variable. A variable in C can be assigned the value in the form of a literal, another variable, or an expression.

The value to be assigned forms the right-hand operand, whereas the variable to be assigned should be the operand to the left of the " = " symbol, which is defined as a simple assignment operator in C.

In addition, C has several augmented assignment operators.

The following table lists the assignment operators supported by the C language −

Operator Description Example
= Simple assignment operator. Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C
+= Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A
*= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A
/= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A
%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A
<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator. C &= 2 is same as C = C & 2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2
|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2

Simple Assignment Operator (=)

The = operator is one of the most frequently used operators in C. As per the ANSI C standard, all the variables must be declared in the beginning. Variable declaration after the first processing statement is not allowed.

You can declare a variable to be assigned a value later in the code, or you can initialize it at the time of declaration.

You can use a literal, another variable, or an expression in the assignment statement.

Once a variable of a certain type is declared, it cannot be assigned a value of any other type. In such a case the C compiler reports a type mismatch error.

In C, the expressions that refer to a memory location are called "lvalue" expressions. A lvalue may appear as either the left-hand or right-hand side of an assignment.

On the other hand, the term rvalue refers to a data value that is stored at some address in memory. A rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.

Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side. Take a look at the following valid and invalid statements −

Augmented Assignment Operators

In addition to the = operator, C allows you to combine arithmetic and bitwise operators with the = symbol to form augmented or compound assignment operator. The augmented operators offer a convenient shortcut for combining arithmetic or bitwise operation with assignment.

For example, the expression "a += b" has the same effect of performing "a + b" first and then assigning the result back to the variable "a".

Run the code and check its output −

Similarly, the expression "a <<= b" has the same effect of performing "a << b" first and then assigning the result back to the variable "a".

Here is a C program that demonstrates the use of assignment operators in C −

When you compile and execute the above program, it will produce the following result −

Learn C practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn c interactively.

The best way to learn C programming is by practicing examples. The page contains examples on basic concepts of C programming. You are advised to take the references from these examples and try them on your own.

All the programs on this page are tested and should work on all platforms.

Want to learn C Programming by writing code yourself? Enroll in our Interactive C Course for FREE.

  • C Program to Create Pyramids and Patterns
  • C Program to Check Prime Number
  • C Program to Check Palindrome Number
  • C Program to Print Hello World
  • C "Hello, World!" Program
  • C Program to Print an Integer (Entered by the User)
  • C Program to Add Two Integers
  • C Program to Multiply Two Floating-Point Numbers
  • C Program to Find ASCII Value of a Character
  • C Program to Compute Quotient and Remainder
  • C Program to Find the Size of int, float, double and char
  • C Program to Demonstrate the Working of Keyword long
  • C Program to Swap Two Numbers
  • C Program to Check Whether a Number is Even or Odd
  • C Program to Check Whether a Character is a Vowel or Consonant
  • C Program to Find the Largest Number Among Three Numbers
  • C Program to Find the Roots of a Quadratic Equation
  • C Program to Check Leap Year
  • C Program to Check Whether a Number is Positive or Negative
  • C Program to Check Whether a Character is an Alphabet or not
  • C Program to Calculate the Sum of Natural Numbers
  • C Program to Find Factorial of a Number
  • C Program to Generate Multiplication Table
  • C Program to Display Fibonacci Sequence
  • C Program to Find GCD of two Numbers
  • C Program to Find LCM of two Numbers
  • C Program to Display Characters from A to Z Using Loop
  • C Program to Count Number of Digits in an Integer
  • C Program to Reverse a Number
  • C Program to Calculate the Power of a Number
  • C Program to Check Whether a Number is Palindrome or Not
  • C Program to Check Whether a Number is Prime or Not
  • C Program to Display Prime Numbers Between Two Intervals
  • C Program to Check Armstrong Number
  • C Program to Display Armstrong Number Between Two Intervals
  • C Program to Display Factors of a Number
  • C Program to Make a Simple Calculator Using switch...case
  • C Program to Display Prime Numbers Between Intervals Using Function
  • C Program to Check Prime or Armstrong Number Using User-defined Function
  • C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
  • C Program to Find the Sum of Natural Numbers using Recursion
  • C Program to Find Factorial of a Number Using Recursion
  • C Program to Find G.C.D Using Recursion
  • C Program to Convert Binary Number to Decimal and vice-versa
  • C Program to Convert Octal Number to Decimal and vice-versa
  • C Program to Convert Binary Number to Octal and vice-versa
  • C Program to Reverse a Sentence Using Recursion
  • C program to calculate the power using recursion
  • C Program to Calculate Average Using Arrays
  • C Program to Find Largest Element in an Array
  • C Program to Calculate Standard Deviation
  • C Program to Add Two Matrices Using Multi-dimensional Arrays
  • C Program to Multiply Two Matrices Using Multi-dimensional Arrays
  • C Program to Find Transpose of a Matrix
  • C Program to Multiply two Matrices by Passing Matrix to a Function
  • C Program to Access Array Elements Using Pointer
  • C Program Swap Numbers in Cyclic Order Using Call by Reference
  • C Program to Find Largest Number Using Dynamic Memory Allocation
  • C Program to Find the Frequency of Characters in a String
  • C Program to Count the Number of Vowels, Consonants and so on
  • C Program to Remove all Characters in a String Except Alphabets
  • C Program to Find the Length of a String
  • C Program to Concatenate Two Strings
  • C Program to Copy String Without Using strcpy()
  • C Program to Sort Elements in Lexicographical Order (Dictionary Order)
  • C Program to Store Information of a Student Using Structure
  • C Program to Add Two Distances (in inch-feet system) using Structures
  • C Program to Add Two Complex Numbers by Passing Structure to a Function
  • C Program to Calculate Difference Between Two Time Periods
  • C Program to Store Information of Students Using Structure
  • C Program to Store Data in Structures Dynamically
  • C Program to Write a Sentence to a File
  • C Program to Read the First Line From a File
  • C Program to Display its own Source Code as Output
  • C Program to Print Pyramids and Patterns

01 Career Opportunities

02 beginner, 03 intermediate, 04 advanced, 05 training programs, c programming assignment operators, free c programming online course with certificate, what is an assignment operator in c, types of assignment operators in c.

1. Simple Assignment Operator (=)

Example of simple assignment operator.

2. Compound Assignment Operators

+=addition assignmentIt adds the right operand to the left operand and assigns the result to the left operand.
-=subtraction assignmentIt subtracts the right operand from the left operand and assigns the result to the left operand.
*=multiplication assignmentIt multiplies the right operand with the left operand and assigns the result to the left operand
/=division assignmentIt divides the left operand with the right operand and assigns the result to the left operand.
%=modulo assignmentIt takes modulus using two operands and assigns the result to the left operand.

Example of Augmented Arithmetic and Assignment Operators

&=bitwise AND assignmentIt performs the bitwise AND operation on the variable with the value on the right
|=bitwise OR assignmentIt performs the bitwise OR operation on the variable with the value on the right
^=bitwise XOR assignmentIt performs the bitwise XOR operation on the variable with the value on the right
<<=bitwise left shift assignmentShifts the bits of the variable to the left by the value on the right
>>=bitwise right shift assignmentShifts the bits of the variable to the right by the value on the right

Example of Augmented Bitwise and Assignment Operators

Practice problems on assignment operators in c, 1. what will the value of "x" be after the execution of the following code, 2. after executing the following code, what is the value of the number variable, benefits of using assignment operators, best practices and tips for using the assignment operator, live classes schedule.

Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast
Filling Fast

About Author

  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Preprocessors
  • C File Handling
  • C Cheatsheet
  • C Interview Questions

Assignment Operators in C

c language multiple assignment

Assignment operators are used for assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error.

Different types of assignment operators are shown below:

1. “=”: This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example:

2. “+=” : This operator is combination of ‘+’ and ‘=’ operators. This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 5. Then (a += 6) = 11.

3. “-=” This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the value on the right from the current value of the variable on left and then assigns the result to the variable on the left. Example:

If initially value stored in a is 8. Then (a -= 6) = 2.

4. “*=” This operator is combination of ‘*’ and ‘=’ operators. This operator first multiplies the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 5. Then (a *= 6) = 30.

5. “/=” This operator is combination of ‘/’ and ‘=’ operators. This operator first divides the current value of the variable on left by the value on the right and then assigns the result to the variable on the left. Example:

If initially value stored in a is 6. Then (a /= 2) = 3.

Below example illustrates the various Assignment Operators:

Please Login to comment...

Similar reads.

  • C-Operators
  • cpp-operator
  • How to Get a Free SSL Certificate
  • Best SSL Certificates Provider in India
  • Elon Musk's xAI releases Grok-2 AI assistant
  • What is OpenAI SearchGPT? How it works and How to Get it?
  • Content Improvement League 2024: From Good To A Great Article

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

PrepBytes Blog

ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING

Sign in to your account

Forgot your password?

Login via OTP

We will send you an one time password on your mobile number

An OTP has been sent to your mobile number please verify it below

Register with PrepBytes

Assignment operator in c.

' src=

Last Updated on June 23, 2023 by Prepbytes

c language multiple assignment

This type of operator is employed for transforming and assigning values to variables within an operation. In an assignment operation, the right side represents a value, while the left side corresponds to a variable. It is essential that the value on the right side has the same data type as the variable on the left side. If this requirement is not fulfilled, the compiler will issue an error.

What is Assignment Operator in C language?

In C, the assignment operator serves the purpose of assigning a value to a variable. It is denoted by the equals sign (=) and plays a vital role in storing data within variables for further utilization in code. When using the assignment operator, the value present on the right-hand side is assigned to the variable on the left-hand side. This fundamental operation allows developers to store and manipulate data effectively throughout their programs.

Example of Assignment Operator in C

For example, consider the following line of code:

Types of Assignment Operators in C

Here is a list of the assignment operators that you can find in the C language:

Simple assignment operator (=): This is the basic assignment operator, which assigns the value on the right-hand side to the variable on the left-hand side.

Addition assignment operator (+=): This operator adds the value on the right-hand side to the variable on the left-hand side and assigns the result back to the variable.

x += 3; // Equivalent to x = x + 3; (adds 3 to the current value of "x" and assigns the result back to "x")

Subtraction assignment operator (-=): This operator subtracts the value on the right-hand side from the variable on the left-hand side and assigns the result back to the variable.

x -= 4; // Equivalent to x = x – 4; (subtracts 4 from the current value of "x" and assigns the result back to "x")

* Multiplication assignment operator ( =):** This operator multiplies the value on the right-hand side with the variable on the left-hand side and assigns the result back to the variable.

x = 2; // Equivalent to x = x 2; (multiplies the current value of "x" by 2 and assigns the result back to "x")

Division assignment operator (/=): This operator divides the variable on the left-hand side by the value on the right-hand side and assigns the result back to the variable.

x /= 2; // Equivalent to x = x / 2; (divides the current value of "x" by 2 and assigns the result back to "x")

Bitwise AND assignment (&=): The bitwise AND assignment operator "&=" performs a bitwise AND operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x &= 3; // Binary: 0011 // After bitwise AND assignment: x = 1 (Binary: 0001)

Bitwise OR assignment (|=): The bitwise OR assignment operator "|=" performs a bitwise OR operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x |= 3; // Binary: 0011 // After bitwise OR assignment: x = 7 (Binary: 0111)

Bitwise XOR assignment (^=): The bitwise XOR assignment operator "^=" performs a bitwise XOR operation between the value on the left-hand side and the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x ^= 3; // Binary: 0011 // After bitwise XOR assignment: x = 6 (Binary: 0110)

Left shift assignment (<<=): The left shift assignment operator "<<=" shifts the bits of the value on the left-hand side to the left by the number of positions specified by the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x <<= 2; // Binary: 010100 (Shifted left by 2 positions) // After left shift assignment: x = 20 (Binary: 10100)

Right shift assignment (>>=): The right shift assignment operator ">>=" shifts the bits of the value on the left-hand side to the right by the number of positions specified by the value on the right-hand side. It then assigns the result back to the left-hand side variable.

x >>= 2; // Binary: 101 (Shifted right by 2 positions) // After right shift assignment: x = 5 (Binary: 101)

Conclusion The assignment operator in C, denoted by the equals sign (=), is used to assign a value to a variable. It is a fundamental operation that allows programmers to store data in variables for further use in their code. In addition to the simple assignment operator, C provides compound assignment operators that combine arithmetic or bitwise operations with assignment, allowing for concise and efficient code.

FAQs related to Assignment Operator in C

Q1. Can I assign a value of one data type to a variable of another data type? In most cases, assigning a value of one data type to a variable of another data type will result in a warning or error from the compiler. It is generally recommended to assign values of compatible data types to variables.

Q2. What is the difference between the assignment operator (=) and the comparison operator (==)? The assignment operator (=) is used to assign a value to a variable, while the comparison operator (==) is used to check if two values are equal. It is important not to confuse these two operators.

Q3. Can I use multiple assignment operators in a single statement? No, it is not possible to use multiple assignment operators in a single statement. Each assignment operator should be used separately for assigning values to different variables.

Q4. Are there any limitations on the right-hand side value of the assignment operator? The right-hand side value of the assignment operator should be compatible with the data type of the left-hand side variable. If the data types are not compatible, it may lead to unexpected behavior or compiler errors.

Q5. Can I assign the result of an expression to a variable using the assignment operator? Yes, it is possible to assign the result of an expression to a variable using the assignment operator. For example, x = y + z; assigns the sum of y and z to the variable x.

Q6. What happens if I assign a value to an uninitialized variable? Assigning a value to an uninitialized variable will initialize it with the assigned value. However, it is considered good practice to explicitly initialize variables before using them to avoid potential bugs or unintended behavior.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

  • Linked List
  • Segment Tree
  • Backtracking
  • Dynamic Programming
  • Greedy Algorithm
  • Operating System
  • Company Placement
  • Interview Tips
  • General Interview Questions
  • Data Structure
  • Other Topics
  • Computational Geometry
  • Game Theory

Related Post

Null character in c, ackermann function in c, median of two sorted arrays of different size in c, number is palindrome or not in c, implementation of queue using linked list in c, c program to replace a substring in a string.

C Programming MCQ (Multiple Choice Questions)

Here are 1000 MCQs on C Programming (Chapterwise) .

33. What is meant by ‘a’ in the following C operation?

34. What will be the output of the following C code?

  • #include <stdio.h>
  • int main ( )
  • int y = 10000 ;
  • int y = 34 ;
  • printf ( "Hello World! %d \n " , y ) ;

35. What will happen if the following C code is executed?

  • int main = 3 ;
  • printf ( "%d" , main ) ;

36. What will be the output of the following C code?

  • signed char chr ;
  • chr = 128 ;
  • printf ( "%d \n " , chr ) ;

37. What will be the output of the following C code on a 64 bit machine?

  • union Sti s ;
  • printf ( "%d" , sizeof ( s ) ) ;

38. What will be the output of the following C function?

  • enum birds { SPARROW , PEACOCK , PARROT } ;
  • enum animals { TIGER = 8 , LION , RABBIT , ZEBRA } ;
  • enum birds m = TIGER ;
  • printf ( "%d \n " , k ) ;

39. What will be the output of the following C code?

  • int const print ( )
  • printf ( "Sanfoundry.com" ) ;
  • void main ( )
  • print ( ) ;

40. Will the following C code compile without any error?

  • for ( int k = 0 ; k < 10 ; k ++ ) ;

41. What will be the final value of x in the following C code?

  • int x = 5 * 9 / 3 + 9 ;

42. What will be the output of the following C code? (Initial values: x= 7, y = 8)

  • printf ( "enter two numbers \n " ) ;
  • scanf ( "%f %f" , & x , & y ) ;
  • printf ( "%f, %d" , x , y ) ;

43. What will be the output of the following C code considering the size of a short int is 2, char is 1 and int is 4 bytes?

  • short int i = 20 ;
  • char c = 97 ;
  • printf ( "%d, %d, %d \n " , sizeof ( i ) , sizeof ( c ) , sizeof ( c + i ) ) ;

44. What is the difference between the following 2 C codes?

  • #include <stdio.h> //Program 1
  • int d , a = 1 , b = 2 ;
  • d = a ++ + ++ b ;
  • printf ( "%d %d %d" , d , a , b ) ;
  • #include <stdio.h> //Program 2
  • d = a ++ +++ b ;

45. What will be the output of the following C code snippet?

  • 1 < 2 ? return 1 : return 2 ;

46. What will be the value of the following assignment expression?

47. What will be the output of the following C function?

  • void reverse ( int i ) ;
  • reverse ( 1 ) ;
  • void reverse ( int i )
  • if ( i > 5 )
  • printf ( "%d " , i ) ;
  • return reverse ( ( i ++, i ) ) ;

48. What will be the final values of i and j in the following C code?

  • int x = 0 ;
  • int f ( )
  • if ( x == 0 )
  • return x + 1 ;
  • return x - 1 ;
  • int g ( )
  • return x ++;
  • int i = ( f ( ) + g ( ) ) | g ( ) ; //bitwise or
  • int j = g ( ) | ( f ( ) + g ( ) ) ; //bitwise or

49. Comment on the following C statement.

50. How many times i value is checked in the following C program?

  • int i = 0 ;
  • while ( i < 3 )
  • printf ( "In while loop \n " ) ;

51. What will be the output of the following C code?

  • if ( i == 2 )
  • printf ( "In while loop " ) ;
  • } while ( i < 2 ) ;
  • printf ( "%d \n " , i ) ;

52. What will be the data type returned for the following C function?

  • int func ( )
  • return ( double ) ( char ) 5.0 ;

53. What is the problem in the following C declarations?

54. Which option should be selected to work the following C expression?

55. What is the meaning of the following C statement?

56. What are the elements present in the array of the following C code?

57. What will be the output of the following C function when EOF returns?

58. Which part of the program address space is p stored in the following C code?

  • p = & i ;

59. Which of the following sequences are unaccepted in C language? a)

59. Comment on the output of following C code.

  • main ( )
  • char * p = 0 ;
  • * p = 'a' ;
  • printf ( "value in pointer p is %c \n " , * p ) ;

60. What is the output of this C code?

  • if ( sizeof ( int ) > - 1 )
  • printf ( "True" ) ;
  • printf ( "False" ) ;

61. What is the output of this C code?

  • char * p = "Sanfoundry C-Test" ;
  • p [ 0 ] = 'a' ;
  • p [ 1 ] = 'b' ;
  • printf ( "%s" , p ) ;

62. What is the output of this C code?

  • float f = 0.1 ;
  • if ( f == 0.1 )

63. What is the output of this C code?

  • int n = 0 , m = 0 ;
  • if ( n > 0 )
  • if ( m > 0 )

Chapterwise Multiple Choice Questions on C Programming

C MCQ - Multiple Choice Questions and Answers

  • C Data Types, Operators and Expressions
  • Control Flow Statements in C
  • C Functions and Structure of a Program
  • C Pointers and Arrays
  • Structures, Unions and Bit-Fields in C
  • C Input and Output
  • Floating Point & Sizeof Operator in C
  • Enumerations and Typedefs in C
  • C String Operations
  • Dynamic Memory Allocation in C
  • C Preprocessor
  • Miscellaneous Topics in C

1. C MCQs on Data Types, Operators and Expressions

The section contains C MCQs on variable names, datatypes, constants, declarations, arithmetic operators, relational and logical operators, type conversions, bitwise operators, assignment operators, increment and decrement operators, conditional expressions, evaluation order and precedence.

2. Multiple Choice Questions on Control Flow Statements in C

The section contains C Language multiple choice questions on switch statements, if-then-else statements, for and while loops, break and continue, goto and labels.

3. MCQs on C Functions and Structure of a Program

The section contains C MCQs on functions basics, external variables, variable scope, static and register variables, automatic variables, c-preprocessor, file inclusion, macro substitution and conditional inclusion.

4. Multiple Choice Questions on Pointers and Arrays in C

The section contains C Programming multiple choice questions and answers on pointers and addresses, function arguments, arrays, address arithmetic, character pointers and functions, multidimensional arrays, pointer arrays initialization, command line arguments and complicated declarations.

5. C MCQs on Structures, Unions and Bit-Fields

The section contains C language MCQs on structures basics, functions, arrays of structures, pointer to structires, self referential structures, table lookup, typedefs, unions and bit fields.

6. Multiple Choice Questions on C Input and Output

The section contains C multiple choice questions and answers on standard input and output, formatted input and output, variable length argument, file access, error handling, line input and output, string operations, character class testing, ungetc, storage management, mathematical functions, random number generation, file operations, printf and scanf.

7. MCQs on Floating Point & Sizeof Operator in C

The section contains C Language MCQs on float datatype and sizeof keyword.

8. Multiple Choice Questions on Enumerations and Typedefs in C

The section contains C multiple choice questions and answers on enums and typedef.

9. C MCQs on String Operations

The section contains C MCQs on string operations, character and error handling.

10. Multiple Choice Questions on C Library

The section contains C multiple choice questions and answers on mathematical functions, general utilities, diagnostics, variable argument lists, non local jumps, localization, signal handling, standard definition, implementation defined limits, date and time functions.

11. C MCQs on Dynamic Memory Allocation

The section contains C MCQs on static and dynamic memory allocation, dma functions, memory leak and dangling pointers.

12. Multiple Choice Questions on C Preprocessor

The section contains C multiple choice questions and answers on pragma, stringizers, conditional preprocessor directives and token concatenation.

13. Miscellaneous Topics in C

The section contains C MCQ questions on inline, endianness, recursion and signed qualifier.

  • C++ Programming MCQ Questions
  • Java Programming MCQ Questions
  • Object Oriented Programming MCQ Questions
  • R Programming MCQ Questions
  • Programming MCQ Questions
  • JavaScript MCQ Questions
  • PHP MCQ Questions
  • Python MCQ Questions
  • Visual Basic MCQ Questions
  • LISP MCQ Questions

Manish Bhojasia - Founder & CTO at Sanfoundry

C Functions

C structures, c reference.

C is a general-purpose programming language that has been widely used for over 50 years.

C is very powerful; it has been used to develop operating systems, databases, applications, etc.

Examples in Each Chapter

Our "Try it Yourself" editor makes it easy to learn C. You can edit code and view the result in your browser:

Click on the "Try it Yourself" button to see how it works.

We recommend reading this tutorial, in the sequence listed in the left menu.

C Exercises

Test yourself with exercises.

Insert the missing part of the code below to output "Hello World!".

Start the Exercise

Advertisement

Learn by taking a quiz! The quiz will give you a signal of how much you know about C.

Start C Quiz

My Learning

Track your progress with the free "My Learning" program here at W3Schools.

Log in to your account, and start earning points!

This is an optional feature. You can study at W3Schools without using My Learning.

Track your progress with at W3Schools.com

Learn by Examples

Learn by examples! This tutorial supplements all explanations with clarifying examples.

See All C Examples

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

Next: Unions , Previous: Overlaying Structures , Up: Structures   [ Contents ][ Index ]

15.13 Structure Assignment

Assignment operating on a structure type copies the structure. The left and right operands must have the same type. Here is an example:

Notionally, assignment on a structure type works by copying each of the fields. Thus, if any of the fields has the const qualifier, that structure type does not allow assignment:

See Assignment Expressions .

When a structure type has a field which is an array, as here,

structure assigment such as r1 = r2 copies array fields’ contents just as it copies all the other fields.

This is the only way in C that you can operate on the whole contents of a array with one operation: when the array is contained in a struct . You can’t copy the contents of the data field as an array, because

would convert the array objects (as always) to pointers to the zeroth elements of the arrays (of type struct record * ), and the assignment would be invalid because the left operand is not an lvalue.

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Does C support multiple assignment of the type a , b = 0, 1 like python does?

The following code gives output : 0 1 and obviously does not raise any error. Does C support the same?

  • variable-assignment
  • multiple-assignment

chtnnh's user avatar

  • 2 No. The closest it comes is this . –  meowgoesthedog Commented Sep 4, 2018 at 14:59
  • 1 Often when a language does not support a feature of interest, it means that the language has other ways to approach the higher level problem. What is the need to do multiple assignments? –  chux - Reinstate Monica Commented Sep 4, 2018 at 15:31
  • @chux I needed to interchange the values of 3 variables inside the body of my for loop –  chtnnh Commented Sep 4, 2018 at 15:36
  • You can do something like this: void AssignValues(int values[], ... ); which would let you implement the first line like this: int vals[]={0,1};AssignValues(vals, a, b); but implementing it would be.... nasty. –  Tim Randall Commented Sep 4, 2018 at 18:35

3 Answers 3

No, C does not support multiple-assignment, nor has it language-level support for tuples.

The above is, considering operator precedence , equivalent to:

Which is equivalent to:

The closest C-equivalent to your Python code would be:

That would be needlessly complex and confusing though, thus prefer separating it into two statements for much cleaner code:

Deduplicator's user avatar

C does not support list assignments as Python does. You need to assign to each variable separately:

dbush's user avatar

No C does not support multiple assignments like this.

Compilation passes since a , b = 0 , 1 is grouped as a, (b = 0), 1 . a and 1 are no-ops but still valid expressions; the expression is equivalent to

with a not changed.

Interestingly, you can achieve your desired notation in C++ with some contrivance and a minor change in the syntax.

Bathsheba's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged c variable-assignment multiple-assignment or ask your own question .

  • The Overflow Blog
  • Where does Postgres fit in a world of GenAI and vector databases?
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Manifest Mind vs Shatter
  • about flag changes in 16-bit calculations on the MC6800
  • How can judicial independence be jeopardised by politicians' criticism?
  • Two way ANOVA or two way repeat measurement ANOVA
  • Why is {_Integer..} matching {_Rule..}?
  • Why does flow separation cause an increase in pressure drag?
  • Is having negative voltages on a MOSFET gate a good idea?
  • What happens if all nine Supreme Justices recuse themselves?
  • Can a 2-sphere be squashed flat?
  • How can these humans cross the ocean(s) at the first possible chance?
  • Stuck on Sokoban
  • Is there a phrase for someone who's really bad at cooking?
  • Regression techniques for a “triangular” scatterplot
  • How to reply to reviewers who ask for more work by responding that the paper is complete as it stands?
  • What to do when 2 light switches are too far apart for the light switch cover plate?
  • Encode a VarInt
  • Using conditionals within \tl_put_right from latex3 explsyntax
  • Chromatic homotopy + algebraic geometry =?
  • Is This Tree A Major Foundation Issue?
  • Do the amplitude and frequency of gravitational waves emitted by binary stars change as the stars get closer together?
  • Which programming language/environment pioneered row-major array order?
  • How would you say a couple of letters (as in mail) if they're not necessarily letters?
  • What would be non-slang equivalent of "copium"?
  • Should I report a review I suspect to be AI-generated?

c language multiple assignment

COMMENTS

  1. c

    (Note that this sequencing freedom is specific to C language, in which the result of an assignment in an rvalue. In C++ assignment evaluates to an lvalue, which requires "chained" assignments to be sequenced.) ... Because, the multiple assignment translates to: sample2 = 0; sample1 = sample2; So instead of 2 initializations you do only one and ...

  2. expression

    But C language treats the multiple assignments like a chain, like this: In C, "X = Y = Z" means that the value of Z must be first assigned to Y, and then the value of Y must be assigned to X. Here is a sample program to see how the multiple assignments in single line work:

  3. C

    Using , operator you can assign a value to a variable multiple times. e.g. K = 20, K = 30; This will assign 30 to K overwriting the previous value of 20. I thought it's invalid to change a variable more than one time in one statement. Yes it leads to undefined behavior if we try to modify a variable more than once in a same C statement but here ...

  4. How expression a=b=c (Multiple Assignment) evaluates in C programming?

    Before Multiple Assignent a=0,b=0,c=100 After Multiple Assignent a=100,b=100,c=100 Assigning a value to multiple variables of same type By using such kind of expression we can easily assign a value to multiple variables of same data type, for example - if we want to assign 0 to integer variables a , b , c and d ; we can do it by following ...

  5. Assignment operators

    Assignment performs implicit conversion from the value of rhs to the type of lhs and then replaces the value in the object designated by lhs with the converted value of rhs . Assignment also returns the same value as what was stored in lhs (so that expressions such as a = b = c are possible). The value category of the assignment operator is non ...

  6. C Exercises

    C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and a clean style, these features make C language suitable for sys

  7. Assignment Operators in C

    Simple assignment operator. Assigns values from right side operands to left side operand. C = A + B will assign the value of A + B to C. +=. Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A. -=.

  8. Operators in C

    Operators are symbols used for performing some kind of operation in C. There are six types of operators, Arithmetic Operators, Relational Operators, Logical Operators, Bitwise Operators, Assignment Operators, and Miscellaneous Operators. Operators can also be of type unary, binary, and ternary according to the number of operators they are using.

  9. C Examples

    Program. C Program to Print an Integer (Entered by the User) C Program to Add Two Integers. C Program to Multiply Two Floating-Point Numbers. C Program to Find ASCII Value of a Character. C Program to Compute Quotient and Remainder. C Program to Find the Size of int, float, double and char. C Program to Demonstrate the Working of Keyword long.

  10. C Programming Assignment Operators

    Assignment Operators in C are used to assign values to the variables. They come under the category of binary operators as they require two operands to operate upon. The left side operand is called a variable and the right side operand is the value. The value on the right side of the "=" is assigned to the variable on the left side of "=".

  11. Operator Precedence and Associativity in C

    The concept of operator precedence and associativity in C helps in determining which operators will be given priority when there are multiple operators in the expression. It is very common to have multiple operators in C language and the compiler first evaluates the operater with higher precedence. It helps to maintain the ambiguity of the ...

  12. Assignment Operators in C

    1. "=": This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example: a = 10; b = 20; ch = 'y'; 2. "+=": This operator is combination of '+' and '=' operators.This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left.

  13. Practice C

    Solve these beginner friendly problems online to get better at C language. Courses. Learn Python 10 courses. Learn C++ 9 courses. Learn C 9 courses. Learn ... Single vs Multiple Lines Quiz: Easy: Basic Expression Printing Test: Easy: String Formatting Exercise ... Variable Assignment : Easy: What is the output: Easy: Output The Difference - MCQ ...

  14. C Operators

    Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions. The return value of a comparison is either 1 or 0, which means true ( 1) or false ( 0 ). These values are known as Boolean values, and you will learn more about them in the Booleans and If ...

  15. C Declare Multiple Variables

    C Exercises. Test Yourself With Exercises. Exercise: Fill in the missing parts to create three variables of the same type, using a comma-separated list: myNum1 = 10 myNum2 = 15 myNum3 = 25; printf("%d", myNum1 + myNum2 + myNum3); Submit Answer ». Start the Exercise. Previous Next .

  16. Assignment Operator in C

    Types of Assignment Operators in C. Here is a list of the assignment operators that you can find in the C language: Simple assignment operator (=): This is the basic assignment operator, which assigns the value on the right-hand side to the variable on the left-hand side. Example: int x = 10; // Assigns the value 10 to the variable "x"

  17. C MCQ (Multiple Choice Questions)

    What will be the value of the following assignment expression? (x = foo())!= 1 considering foo() returns 2. a) 2 b) True c) 1 d) 0 View Answer. Answer: c ... Multiple Choice Questions on Control Flow Statements in C. The section contains C Language multiple choice questions on switch statements, if-then-else statements, for and while loops ...

  18. C Tutorial

    Test yourself with multiple choice questions. Get Certified. Document your knowledge. ... Learn C. C is a general-purpose programming language that has been widely used for over 50 years. C is very powerful; it has been used to develop operating systems, databases, applications, etc.

  19. Structure Assignment (GNU C Language Manual)

    15.13 Structure Assignment. Assignment operating on a structure type copies the structure. The left and right operands must have the same type. Here is an example: Notionally, assignment on a structure type works by copying each of the fields. Thus, if any of the fields has the const qualifier, that structure type does not allow assignment:

  20. Does C support multiple assignment of the type a , b = 0, 1 like python

    1. No C does not support multiple assignments like this. Compilation passes since a , b = 0 , 1 is grouped as a, (b = 0), 1. a and 1 are no-ops but still valid expressions; the expression is equivalent to. b = 0. with a not changed. Interestingly, you can achieve your desired notation in C++ with some contrivance and a minor change in the syntax.