Podcast
Questions and Answers
What is the maximum number of characters allowed in a variable name?
What is the maximum number of characters allowed in a variable name?
Which of the following is a valid variable name?
Which of the following is a valid variable name?
What should a variable name not be?
What should a variable name not be?
What is the correct syntax for declaring multiple integer variables in C?
What is the correct syntax for declaring multiple integer variables in C?
Signup and view all the answers
What symbol is used to assign a value to a variable in C?
What symbol is used to assign a value to a variable in C?
Signup and view all the answers
Which of the following types of constants is NOT recognized in C?
Which of the following types of constants is NOT recognized in C?
Signup and view all the answers
In C, what type of variable retains its value even after the block in which it is declared has exited?
In C, what type of variable retains its value even after the block in which it is declared has exited?
Signup and view all the answers
How many types of variables are identified in C programming?
How many types of variables are identified in C programming?
Signup and view all the answers
Which of the following is a valid decimal constant?
Which of the following is a valid decimal constant?
Signup and view all the answers
What is a requirement for octal constants in C programming?
What is a requirement for octal constants in C programming?
Signup and view all the answers
In C programming, which of the following is NOT a valid hexadecimal constant?
In C programming, which of the following is NOT a valid hexadecimal constant?
Signup and view all the answers
How must hexadecimal constants be prefixed?
How must hexadecimal constants be prefixed?
Signup and view all the answers
Which of the following represents a valid floating point constant?
Which of the following represents a valid floating point constant?
Signup and view all the answers
Which statement about integer constants in C programming is FALSE?
Which statement about integer constants in C programming is FALSE?
Signup and view all the answers
Identify the correct digits that can be used in octal constants.
Identify the correct digits that can be used in octal constants.
Signup and view all the answers
Floating point constants in C can be expressed in which of the following forms?
Floating point constants in C can be expressed in which of the following forms?
Signup and view all the answers
What is the main purpose of the increment operator?
What is the main purpose of the increment operator?
Signup and view all the answers
Which statement about the increment operator is false?
Which statement about the increment operator is false?
Signup and view all the answers
In the expression 'b = ++y', what value does 'b' take if 'y' is initially 5?
In the expression 'b = ++y', what value does 'b' take if 'y' is initially 5?
Signup and view all the answers
What does the post-increment operator do in the expression 'b = x++' when 'x' is 5?
What does the post-increment operator do in the expression 'b = x++' when 'x' is 5?
Signup and view all the answers
Which of the following statements is true about pre-increment and post-increment operators?
Which of the following statements is true about pre-increment and post-increment operators?
Signup and view all the answers
Why can't the increment operator be used on constant values?
Why can't the increment operator be used on constant values?
Signup and view all the answers
What will happen if you try to execute 'b = ++5' in code?
What will happen if you try to execute 'b = ++5' in code?
Signup and view all the answers
What is the result of the bitwise AND operation between the integers 12 and 25?
What is the result of the bitwise AND operation between the integers 12 and 25?
Signup and view all the answers
What symbol denotes the increment operator?
What symbol denotes the increment operator?
Signup and view all the answers
Which operator is used to perform a bitwise OR operation in C programming?
Which operator is used to perform a bitwise OR operation in C programming?
Signup and view all the answers
What is the outcome of applying the bitwise XOR operator on 12 and 25?
What is the outcome of applying the bitwise XOR operator on 12 and 25?
Signup and view all the answers
When the bitwise complement operator ~ is applied to the number 35, what is the expected result in terms of two's complement?
When the bitwise complement operator ~ is applied to the number 35, what is the expected result in terms of two's complement?
Signup and view all the answers
How is the 2's complement of a binary number derived?
How is the 2's complement of a binary number derived?
Signup and view all the answers
Which of the following best describes the condition for a bit to be 1 in a bitwise OR operation?
Which of the following best describes the condition for a bit to be 1 in a bitwise OR operation?
Signup and view all the answers
What is the correct binary representation of the number 29?
What is the correct binary representation of the number 29?
Signup and view all the answers
In C programming, what would be the output of the statement printf("Output = %d", a | b);
when a is 12 and b is 25?
In C programming, what would be the output of the statement printf("Output = %d", a | b);
when a is 12 and b is 25?
Signup and view all the answers
What is the maximum number of characters that a C identifier can have?
What is the maximum number of characters that a C identifier can have?
Signup and view all the answers
Which of the following is NOT a valid C identifier?
Which of the following is NOT a valid C identifier?
Signup and view all the answers
Which of the following keywords is correctly written?
Which of the following keywords is correctly written?
Signup and view all the answers
What type of data does 'float' represent in C?
What type of data does 'float' represent in C?
Signup and view all the answers
Which of the following is an enumeration data type in C?
Which of the following is an enumeration data type in C?
Signup and view all the answers
Which of the following data types cannot store negative values?
Which of the following data types cannot store negative values?
Signup and view all the answers
How many bytes does the 'double' data type occupy in C?
How many bytes does the 'double' data type occupy in C?
Signup and view all the answers
What does a variable represent in C programming?
What does a variable represent in C programming?
Signup and view all the answers
Which of the following represent basic data types in C?
Which of the following represent basic data types in C?
Signup and view all the answers
What is the range of a 'signed short' in C?
What is the range of a 'signed short' in C?
Signup and view all the answers
Which of these is counted as a derived data type?
Which of these is counted as a derived data type?
Signup and view all the answers
What is a characteristic of keywords in C programming?
What is a characteristic of keywords in C programming?
Signup and view all the answers
What is the maximum value of an 'unsigned int' in C?
What is the maximum value of an 'unsigned int' in C?
Signup and view all the answers
Study Notes
C Identifier Rules
- C compiler only recognizes the first 31 characters of an identifier.
- Identifiers can include alphabets and numbers, but must start with an alphabet.
- Identifiers can use the underscore symbol (
_
) but not other special characters or spaces. - Identifiers cannot be reserved keywords.
Keywords
- Keywords are reserved words with predefined meanings.
- Keywords cannot be used as variable names, constant names, etc.
- All keywords are written in lowercase.
- C has 32 keywords:
auto
,break
,case
,char
,const
,continue
,default
,do
,double
,enum
,else
,extern
,float
,for
,goto
,if
,int
,long
,register
,return
,signed
,short
,static
,sizeof
,struct
,switch
,typedef
,union
,unsigned
,void
,volatile
,while
.
Data Types
- Data types are used to allocate memory for data and specify what type of data a variable can store.
- Four main data types in C:
-
Basic Data Type:
int
,char
,float
,double
-
Derived Data Type:
array
,pointer
,structure
,union
-
Enumeration Data Type:
enum
-
Void Data Type:
void
-
Basic Data Type:
Basic Data Types
- Basic data types are either integer-based or floating-point based.
- Memory size of basic data types may vary depending on 32-bit or 64-bit operating systems.
- Size and ranges of data types with type qualifiers:
Type | Size (bytes) | Range | Control String |
---|---|---|---|
char or signed char |
1 | -128 to 127 | %c |
unsigned char |
1 | 0 to 255 | %c |
int or signed int |
2 | -32768 to 32767 | %d or %i |
unsigned int |
2 | 0 to 65535 | %u |
short int or signed short int |
1 | -128 to 127 | %d or %i |
unsigned short int |
1 | 0 to 255 | %d or %i |
long int or signed long int |
4 | -2147483648 to 2147483647 | %ld |
unsigned long int |
4 | 0 to 4294967295 | %lu |
float |
4 | 3.4E-38 to 3.4E+38 | %f or %g |
double |
8 | 1.7E-308 to 1.7E+308 | %lf |
long double |
10 | 3.4E-4932 to 1.1E+4932 | %Lf |
Variables
- A variable is a name that refers to a memory location used to store data.
- Variables are changeable and their values can be modified during program execution.
Variable Declaration
- Variables must be declared before they are used in a program.
- Syntax:
data_type variable-1, variable-2, ..., variable-n;
- Separated by commas and the declaration ends with a semicolon.
- Example:
int x, y, z;
float a, b;
char m, n;
Assigning Values to Variables
- Values can be assigned to variables using the assignment operator (
=
). - Syntax:
variable = constant;
- Example:
x = 100;
a = 12.25;
m = 'f';
- Values can also be assigned at the time of declaration:
data_type variable = constant;
Types of Variables
- Local Variable: Declared inside a function or block of code. Only accessible within that scope.
- Global Variable: Declared outside of any function. Accessible from anywhere in the program.
-
Static Variable: Declared using the
static
keyword. Retains its value even after the function ends.
Constants
- Constants refer to fixed values that don't change during program execution.
- Also called literals.
- Types of constants in C:
-
Integer Constants:
-
decimal constant (base 10)
: 0, -9, 22, etc. -
octal constant (base 8)
: starts with 0 (e.g., 021, 077, 033). -
hexadecimal constant (base 16)
: starts with 0x (e.g., 0x7f, 0x2a, 0x521).
-
- Real or Floating Point Constants: have fractional or exponential forms (e.g., -2.0, 0.0000234, -0.22E-5).
- Character Constants: enclosed in single quotes (e.g., 'a', 'b', 'c').
- String Constants: enclosed in double quotes (e.g., "hello", "world").
- Backslash Character Constants: special characters represented with a backslash (e.g., '\n' for newline).
-
Integer Constants:
Increment Operators
- Increment operators increase the value of a variable by 1.
- Two types:
-
Pre-Increment: Increments the variable's value before using it in the expression (
++y
). -
Post-Increment: Increments the variable's value after using it in the expression (
x++
).
-
Pre-Increment: Increments the variable's value before using it in the expression (
Bitwise Operators
- Work on individual bits of data.
- Types:
- Bitwise AND (&): Results in 1 if both corresponding bits are 1.
- Bitwise OR (|): Results in 1 if at least one corresponding bit is 1.
- Bitwise XOR (^): Results in 1 if corresponding bits are different.
- Bitwise Complement (~): Inverts each bit (0 to 1, 1 to 0).
2's Complement
- A method used to represent negative numbers in binary.
- The 2's complement of a number is equal to its complement (inverting all bits) plus 1.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge of C programming rules including identifier naming conventions, keyword usage, and data types. This quiz covers the essentials you need to understand to write valid C code effectively.