Skip to main content

Posts

Showing posts with the label variables

Constants and Variables

Constants in C refer to fixed values that do not change during the execution of a program. There are four basic types of constants in C. They are integer constants, floating point constants, character constants and string constants. Integer and floating point constants represent numbers. They are often referred to collectively as numeric _ type constants. The following rules apply to all numeric type constants. 1. Commas and blank spaces cannot be included within the constants. 2. The constant can be preceded by a minus (-) if desired. The minus sign is an operator that changes the sign of a positive constant though it can be thought of as a part of the constant itself. 3. The value of a constant cannot exceed specified minimum and maximum bounds. For each type of constant, these bounds will vary from one C compiler to another. Integer Constants: An integer constant is an integer-valued number. Thus it consists of a sequence of digits. Integer (number) constants can b...

C++ home work

Q1. How do you differentiate variables and identifiers? Answer: A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at different times during execution. Identifiers refer to the names of variables, functions, arrays, classes, etc., created by the programmer. The first character in an identifier must be a letter or the _ (underscore) character; however, beginning identifiers with an underscore is considered poor programming style. Q2. Does C++ provide any ternary operator? If yes, explain its works. Answer: A ternary operator pair “? :” is available in C++ to construct conditional expressions of the form exp1 ? exp2 : exp3; Where,  exp1, exp2, andexp3are expressions. The operator ? : works as follows: exp1 is evaluated first. If it is nonzero (true), then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is fa...