Communicating with a computer involves speaking the computer's language, which rules out English as a language of communication with the computer. However, there is an immediate difference between learning English and learning the c language. The best learning method is to understand the first alphabet, the alphabet combined to form a word, a word combined to form a sentence, and a sentence combined from the paragraph.
figure 1
The c character set
A character denotes any alphabet, digit, or special symbol used to represent information. Figure 1.2 shows valid variable alphabets, numbers, and special symbols allowed in c.
The alphabets, digits, and special symbols, when properly combined, form constants, variables, and keywords. Let us understand the meaning of each of them. A constant is an entity that may change. A keyword is a word that carries a special meaning.
In programming, we typically do many calculations. The result of these calculations is stored in the computer's memory. Like human memory, the computer's memory also consists
of millions of cells. The calculated values are stored in these memory cells. To make the retrieval and usage of these values are stored in the memory cells. To make the retrieval and usage values easy, these memory cells (also called memory location) are given names. Since
the value stored in each location may change, the names given to these to this location are calledvariable names.
Consider the memory locations shown in figure 1.3. Here three are stored in a memory location, and the name x is given to it. Then we have assigned a new value of 5 to the memory location.
x. this would overwrite the earlier value three since a memory location can hold only one weight at a time.
figure 1.3
since the location whose name is X can hold the different values of different times, X is known as a variable.An against this, 3 or 5 do not change, hence are known as constants.
The constant is often called literals in the C programming language, whereas the variable is called identifiers.
Now, let us understand the constant and their variable. But, first, let us see what is different types of constants and variables exist in C.
Types of C constants
C constants can be divided into two major categories:
primary constants
Secondary constants
These constants are further categorized as shown In figure 1.4
Figure 1.6
At this stage, we would restrict our discussion to the only primary constants, namely, integer, natural, and character constants. Let us see the details of each of these constants. For constructing these constants. For creating these different types of constants, specific rules have been laid down. These rules are as under:
Rules for creating Integer constants
A constant integer must have at least one digit.
It must not have a decimal point.
It can be either positive or negative.
If no sign precedes an integer constant, it is assumed to be positive.
No commas or blanks are allowed within an integer constant.
The allowable range for integer constants is -21474836483648 to +2147483647.
The range of an integer constant depends upon the compiler. For compiler like visual studio, GCC, it is -2147483648 to +21474836, whereas, for compilers like turbo c or turbo c++, the range is -32768 to +32767
Ex: 426
+782
-8000
-7605
Rules for constructing real constants
Real constants are often called floating-point constants. The real constants could be written in two forms- Fractional form and exponential form.
Following rules must be observed while constructing real constants expressed in fractional
forms:
a) A real constant must have at least one digit.
b) It must have a decimal point.
c) It could be either positive or negative.
d) default sign is positive.
e) No commands or blanks are allowed within all real constant.
Ex. +325.34
426.0
-32.76
-48.5792
The exponential form is usually used if the value of the constants is either too small or too large. However, it doesn't restrict us from using the exponent form for other real constants.
In the exponential form, the real constants are represented in two parts. The part appearing
before 'e.' is called Manistisaa, whereas the following to "e" is called the exponent.
Following are rules that must be observed while constructing real constants expressed in exponential form:
(a) The mantissa part and the exponential part should be separated by the letter e or E.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a positive or negative sign.
(e) range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
Ex
+3.2e-5
4.1e8
-0.2E+3
-3.2e-5
Rules for constructing character constants
(a) A character construct is a single alphabet, a single-digit digit or a single digit, or a single special symbol enclosed within the single inverted command.
(b) Both the inverted commas should point to the left. For example, 'A' is a valid character constant, whereas 'A' is not.
Ex 'A'
'I'
'5'
'='
Types of C variable
A particular type of variable can hold only the same kind of constant—for example, an integer variable can have only an integer constant, a real variable can hold only a real constant, and a character variable can hold only character constant. Therefore, the rules for constructing different types of constants are different. However, for building the variable name of all kinds, the same set of rules applies. These rules are given below.
Rules for construction variable Names
A variable name is any combination f 1 to 30 alphabets, digits, or underscore. Some compilers allow variable names whose length could be 247 characters. Still, it would be safer to stick to the rule of 31 characters. Don't create unnecessarily long variable names as it adds to your typing efforts.
The first character in character in the variable name must be an alphabet or underscore ( _ ).
No commas or blanks are allowed within a variable name.
No special symbol other than an underscore ( as in grass_sal ) can be used in a variable name.
Since the maximum allowed length of a variable name is 31 characters, many variable names can be constructed using meaningful variable names built using the rules mentioned above.
C keywords
Keywords are the words whose meaning had already been explained to the c compiler. There are only 32 keywords available in c programming. The below table gives a list of these keywords for your reference. A detailed explanation will be taken up in later chapters, whereas their use is relevant.
auto
double
int
struct
break
else
long
switch
Case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue
for
signed
void
default
goto
sizeof
volatile
do
if
static
while
The keywords cannot be used as a variable name because if we do so, we are trying to assign a new meaning to the keyword, which is not allowed. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it is safer not to mix up the variable names and keywords.
In the next post, we will be learning the first c program.
Computer network security is an important aspect of today’s world. Nowadays due to various threats designing security in an organization is an important consideration. It is essential to understand basic security principles, various threats to security, and techniques to address these threats. The student will be able to recognize potential threats to confidentiality, integrity, and availability and also be able to implement various computer security policies. This course will introduce basic cryptographic techniques, fundamentals of computer/network security, Risks faced by computers and networks, security mechanisms, operating system security, secure System design principles, and network security principles. Also, it will create awareness about IT ACT and different Cyber laws. This course aims to help the student to attain the following industry identified competency through various teaching leaming experiences: 3. COURSE OUTCOMES (COs) The theory, practical experiences...
Hi, guys today I will be sharing Object-Oriented Programming in C++(OOP) MCQ for practice and for educational purposes. Students should practice daily with Mcq for practice for downloading the pdf at the last of the post you will find the download button from there you can download the pdf for future reference. 1. High-level languages like C, Fortran are also known as —-. a. procedural languages b. Object oriented language c. form-based language d. both a and b 2. One of the basic concepts in Object Oriented Programming approach is bundling both data and functions into one unit known as —-. a. Simple variable b. object c. bundle d. both a and b 3. Which of the following shows the Operator overloading feature in C++ a. Polymorphism b. inheritance c. message passing d. both a and b 4. One of the alternatives to nested if is the —– a. break statement b. Jump statement c. switch statement d. both a and b 5. In the switch case statement, every case ...
Comments
Post a Comment