C Programming | Constants, Variables & Data Types


Ans. : Information : After converting or processing the data which may consists of numbers, characters, strings etc to something which is useful and make much sense to a person is known as Information. So, information is the converted or processed form of data.

            Program : Program is a set of instructions. The task of processing of data is accomplished by executing a sequence of precise instructions called a program. So program executes instructions to perform task which is specified.

            Syntax rules or grammar : Instructions in a program is written using certain symbols and words according to some rigid rules known as syntax rules or grammar. Each programming language has its own rules that must be followed strictly when using the language.

            Syntax errors : Mistakes in using the syntax rules or grammar of a programming language is known as syntax errors. Syntax errors are must be avoided to get successful execution.

Qus. 02: What is constant ? Write down briefly about different type of constant ?

Ans. : Constants : Constants are of fixed values that do not change during the execution of a program. There are various types of constants. The types are illustrated in the following figure.

Integer constants : An integer constant refers to a sequence of digits. There are three types of integer constants, namely, decimal integer, octal integer and hexadecimal integer.
            Decimal integer consists of a set of digits from 0 to 9, preceded by an optional + or – sign. Examples,      123     -321    0          64932
            Octal integer consists of a set of digits from 0 to 7, with a leading 0. Examples, 037     0      0437         0551
            A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may also includes letters from A to F or from a to f. The letters represents the numbers from 10 to 15.Examples,            0X2     0x9F   0Xbcd    0x

      Real constants : Real constants are used to represent quantities that are very continuously, such as distances, temperature etc. These quantities are represented by numbers containing fractional parts. Examples,      0.00832          -0.75               33.337

      Single character constants : A single character constants contains a single character enclosed within a pair of single quote marks. Example, ‘5’         ‘X’       ‘;’

      String constants : A string constant contains a string of characters enclosed within a pair of double quote marks. Examples,    “Hello !”         “1987”            “?....!”

      Backslash character constants : C supports some special backslash character constants that are used in output functions. For example
                  Constants                                                    Meaning
                        ‘\a’                                                       audible alert (bell)
                        ‘\n’                                                      new line
                        ‘\?’                                                       question mark


Ans. : Character set : The various category of characters are called the character set. In C, the characters are grouped into the following categories.
            (i) Letters.              Uppercase     A..................Z
                                                Lowercase     a...................z
            (ii) Digits. All decimal digits. 0................9
            (iii) Special characters. such as
                        ,           comma
                        .           period
                        ;           semicolon
                        :           colon
          (iv) White spaces. Such as blank spaces, horizontal tab, new line etc.

Qus. 04: What is keyword and identifier ? Give the rules for identifier.

Ans. : Keywords : Keywords have fixed meanings and these meanings can not be changed. There are 32 keywords. Some compiler may use additional keywords that must be identified from the C manual. Keywords serve as basic building block for a program statement.
            Such as, auto, break, double etc. All keyword must be written in lowercase.

      Identifiers : The names of variables, functions and arrays are identifiers. These are user-defined names and consist of a sequence of letters and digits. Such as, my_num, _ton etc.

      Rules for identifier :
(i)          Must consist of only letters, digits and underscores.
(ii)        First character must be an alphabet or underscore.
(iii)      Only first 31 characters are significant.
(iv)      Can not use a keyword.
(v)        Must not contain white spaces.

Qus. 05 : What are variables ? Give the conditions for variables.

Ans. : Variables : A variable is a data name that may be used to store data value. A variable may take different value at different times during execution. Some examples are, average, height, class_strength.

            Conditions for variables : Variable names may consist of letters, digits and the underscore character, subject to the following conditions.
(i)       Must consist of only letters, digits and underscores.
(ii)        First character must be an alphabet. Some system permits underscore as the first character.
(iii)      31 characters are permitted. But only the first 8 characters are significant.
(iv)      Uppercase and lowercase are significant.
(v)        It should not be a keyword.
(vi)      White spaces are not allowed.
(vii)    Keyword may be a part of the variable. such as , int_type.


Ans. : Data types : C language is rich in its data types. ANSI supports three classes of data types.
(i)          Primary or fundamental data types.
(ii)        Derived data types.
(iii)      User-defined data types.
      All C compilers support five fundamental data types. Namely, integer (int), character (char), floating point (float), double-precision floating point (double) and void. They are described below.
           
            Integer types : Integer are whole numbers with a range of values supported by a particular machine. If we use a 16 bit word length, the size of the integer value is limited to the range -32768 to +32767.
            C has three classes of integer storage, namely short int, int and long int. Short int represents fairly small value than int and int represents fairly small value than long int.

            Floating point type : Floating point numbers are stored in 32 bits, with 6 digits of precision. Floating point numbers are defined in C by the keyword float. When float is not sufficient double can be used and when double is not sufficient long double can be used.
    
          Void types : The void types has no values. This is usually used to specify the type of functions. The type of a function is said to be void when it does not return any values to the calling function.

            Character types : A single character can be defined as a character (char) type data. Characters are usually stored in 8 bits of internal storage. While unsigned char have values between 0 to 255, sign char have values from -128 to 127.


ক্রেডিট : তন্ময় চক্রবর্তী

1 comments:

Tanmay Chakrabarty বলেছেন...

Well, you have mentioned the credit. Thats ok, but you could have told once that you are about to copy all my notes here as a book.

Its not a book, its my notes on C programming based on the book of C programming by E. Balaguruswamy.

Ok. Bye.

01. Overview of C

02. Constants, Variables & Data Types

03. Operators & Expressions

04. Managing I/O Operations

05. Decision Making & Branching

06. Decision Making & Looping

07. Arrays

08. User Defined Functions

Comment Please

মন্তব্য..

সবিস্তার সূচীপত্র
টেম্পলেট কাষ্টমাইজেশন - তরঙ্গ ইসলাম | তরঙ্গ ইসলাম