Bifalgorithm post · Computer science one · Declaration & Assignment

How can you declare multiple variables and constants in C?

How can you declare multiple variables and constants in C? (Computer science one · Declaration & Assignment) — "As another shorthand, we can declare multiple v…

Ideas in this flowchart

  • Shorthand for declaring variables and defining constants
  • Multiple variables can be declared on the same line
  • Variables are delimited with commas
  • Variables declared together must have the same type
  • Assignments can be included in the declaration
  • The int declaration can combine variables and assigned values
  • The double declaration can combine variables and an assigned value
  • The const keyword defines a constant
  • A const variable is read-only
  • A constant must be assigned a value at declaration
Feed/

How can you declare multiple variables and constants in C?

No cover

Channel

Computer science one

1 page

"As another shorthand, we can declare multiple variables on the same line by delimiting them with a comma. However, they must be of the same type. We can also use an assignment with them.\n\nint numOrders, numUnits = 42, numCustomers = 10, numItems;\n\ndouble costPerUnit = 32.79, salesTaxRate;\n\nAnother convenient keyword is const, short for “constant.” We can apply it to any variable to indicate that it is a read-only variable. Of course, we must assign it a value at declaration. For example:"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.