Saturday 3 September 2022

Chapter-7 Introduction to C and Basic Structure of C Program

0 comments

 Chapter-7 Introduction to C and Basic Structure of C Program


CHAPTER NO.7 INTRODUCTION TO C AND BASIC STRUCTURE OF C PROGRAM

 

7.1 INTRODUCTION AND HISTORY OF C

C is a general-purpose programming language. C can be used to develop any type of application programs. We can develop Business applications, Scientific applications etc. using it. It can also be used to develop System programs such as Operating Systems, Language Translators etc. Thus, we can say that it is useful for developing both types of software, Le.

System Software and Application Software.In 1960, many computer programming languages were emerged like FORTRAN, COBOL etc. But, these languages were used for specific applications. For example: FORTRAN (FORmula TRANslation) was used to develop Scientific Applications only, while COBOL (COmmon Business Oriented Language) was used to develop Business Applications only. Later an international committee was set up to develop a general purpose programming language. As a result, in 1963, Combined Programming Language (CPL) was developed at Cambridge University. It was hard to leam and difficult to implement. So, later in 1967, BCPL (Basic Combined Programming Language) was developed by Martin Richards at Cambridge  University.Similarly, B language was developed by Ken Thompson at AT & T's Bell Laboratory in 1970.But both of these languages, BCPL and B, are type-less languages and too specific. Finally, in 1972, using many important ideas of BCPL and B languages, Language C was developed by Dennis Ritchie at AT & T's Bell Laboratories of USA and it became a general-purpose programming language.

 

7.2 WHY C-LANGUAGE IS CALLED MIDDLE LEVEL LANGUAGE?

All the programming languages can be divided into two types: Low Level Programming Languages and High Level Programming Languages.

 

Low Level Languages are known as Machine-Oriented Languages because programmers have to concentrate more on the architecture of underlying hardware (machine) rather than on the logic of the program to be solved. It is difficult to leam & use these  programming languages. These languages are used to write machine dependent system programs such as operating system, translators and so-on. Examples of these languages are Assembly Language and Machine Language.

 

High Level Languages are known as Problem-Oriented Languages because programmers have to concentrate more on the logic of the program rather than the hardware architecture of the machine. It is easy to learn and use these  programming languages. These languages are used to write any type of  application programs, such as business applications, scientific applications etc. Examples of these languages are FORTRAN, COBOL, Pascal etc.

 


C Language has the capabilities of these both types of programming languages, ic. Low Level and High Level programming languages. It means C language is well suited for writing both system programs and application programs. Hence, C is a programming language which stands in between the above two types of programming languages. So C is called Middle Level Language.Though, there is no special category of Middle level Programming language, it is only due to the special features of C language why it is designated as Middle Level Programming Language.

 

7.3 INTRODUCTION TO C EDITORS & IDEs

Editors are the programs that are useful for writing source codes of languages. There are many programming languages which have their own editors to write programs, such as C, C++ etc. But some programming languages do not have their own editor for writing programs, such as Java. Java Programming can be written in any simple text editor program. After writing source programs in programming languages, they must be compiled in order to execute by the computer systems. These source programs must be compiled by their respective Compilers.

Many programming languages also support the IDEs. IDE stands for Integrated Development Environment. Integrated Development Environment (IDE) can be defined as software that gives its users an environment for writing programs (Editor), along with tools for compiling,executing, testing and debugging the programs. Usually,Modem IDE Software are very user-friendly. They provide an easy-to-use interface. These IDE interfaces provide suggestions for syntax to programmers, the graphical user interface having buttons and menus to interact with,editors and plugins and many other features.There are many IDEs that are available for programming in C. Some of these common IDEs are given below:

Turbo C * Code Blocks « Eclipse

Code Lite . Net Beans . Dev C++ etc...

 

Tarbo C is one of the oldest IDE for programming in the C language. It was developed by Borland and first introduced in 1987. At the time, Turbo C was known for its compact  size,comprehensive manual, fast compile speed and low price. But now a days, Turbo C was getting out-dated due to the advancements in the newer Operating Systems, such as Windows 7,



Windows 8 and Windows 10. In these operating systems, programmers have been facing many issues while they make C programs in Turbo C due to compatibility issues. Many modern IDEs have been developed for programming in C which works well in modern operating systems.Code::Blocks is also a popular modem IDE for programming in C/C++. It is a free (Open Source), highly extensible and configurable, cross-platform C and C++ IDE. It offers programmers the most demanded and ideal features. It delivers a consistent user interface and feel. Most importantly, we can extend its functionality by using plugins developed by users.

 


Code::Blocks provides many features to programmers which are given below:

It works on Windows, Linux and Mac OS X as well.It supports Compiling, Debugging, Code Coverage, Profiling, Auto-completion of code It provides support for multiple compilers including GCC, mingw, clang, Borland C++ 55, etc.

It is very fast, no need for makefiles

It provide facilities of debugging by supporting full breakpoints including code breakpoints, data breakpoints, breakpoint conditions plus many moredisplay local functions symbols and arguments It is designed to be fully configurable and extensible with its plugins.It provides workspace that supports combining of projects

It supports the feature of Custom memory dump and syntax highlighting It also provides support for code analysis, etc.

 

Code::Blocks IDE can be downloaded from the following link:

http://www.codeblocks.org/downloads

 

Any one of the C/C++ IDE, that are available in market including modem or old ones, can be used for writing C programs of this book.

 

7.4 CREATING AND EXECUTING C PROGRAMS

Any C program development involves the following steps:

1. Design the program

2. Write the program using any Text Editor or IDE supporting C Language

3. Save the program by giving filename with extension .

4. Compile the program

5. It there are any errors in the program, then correct it and repeat the step 4

6. Execute the program.

7. View the Output Window

 

7.5 GETTING STARTED WITH C

For communication with human beings, we use natural languages like English, Hindi, and Punjabi etc. But to communicate with computers, we can use only those languages which a computer system can understand directly or indirectly. These languages are called Programming Languages. C is a programming language. As we have to learn any natural language before using it, similarly we must also have to learn programming languages like C for communication with the computers. Leaming programing languages are very similar to lear any natural language like Hindi, Punjabi etc.

 


There is a very close analogy between learning natural languages (like English, Hindi,Punjabi, etc.) and computer programming languages (like C, C++, JAVA, etc.). The classical method of learning any natural language (for example English) is to learn the alphabets or characters used in the language, then learn to combine these characters to form words, which in turn are combined to form sentences and sentences are combined to form paragraphs. Learning any computer programming language, for example C, is similar and much easier.

 

Therefore, instead of straight-away learning how to write programs, we rust first now what characters, numbers, symbols are used in C, then using these how different tokens are constructed, finally how these tokens are combined to form instructions. A group of instructions would be combined later on to form a program. This analogy of learning natural and computer programming languages can be represented using figure 7.4.

 

 

7.6 CHARACTER SET

It is the first step for leaming any language whether it is Natural or a Computer Programming Language. We can learn any language only if we know which characters and symbols are allowed in that language. So, before learning C, we must be familiar with the characters and

symbols used in the C language. C language supports ASCII (American Standard Code for Information Interchange) character set. The ASCII set of characters includes the following characters and symbols:

Upper and Lower case Alphabets (A to Z, a to z)

Digits (0 to 9)

 

Special Symbols (all the printable symbols present on the keyboards, For Example:

 

Some Non-printable characters, For example: new-line, horizontal-tab etc.

The set of these above characters and symbols is called the Character Set of C Language.

 

7.7 TOKENS

Tokens are like words and punctuation-marks in English language. In any programming language, like C, a program is made up of tokens. Tokens are the smallest individual units in a program. A C-program can have five types of tokens as shown below:



Introduction of these tokens with suitable examples is given below:

 

7.7.1 Keywords

Keywords are also called the Reserve Words. These words are predefined in the Compiler of C Language. Meaning of these words is predefined. They are used for special purposes for which they had been defined. We cannot change their meaning. In Turbo C, these words are shown in white colour while in code::blocks these words are shown in blue colour. C language has 32 keywords but some new compilers introduce some more keywords to C Language.Following is the list of 32 keywords that are supported by all the compilers of C language:

 


These keywords can be used wherever they are required in the program. All the keywords in C programs must be written in lower-case only. As C is case-sensitive language, so if we write these keywords in upper-case in a program, it will display compile errors. (A case sensitive language is a language which considers lower case and upper case alphabets as different elements.)

 

7.7.2 Identifiers

Identifiers are the name given to elements of program such as variables, constants, arrays,functions, structures etc. Every program element must be named to distinguish it from other elements. The name assigned to the elements should be meaningful because it facilitates easy understanding of the program elements. After naming the program elements, they can be identified by their name. For defining names of program elements, some naming rules must be followed during writing of C programs. These naming rules are given below:

 

Identifier name must begin with an alphabet or underscore ( _ } symbol. It must not begin with a digit. For example: Identifier name 5star will be wrong because it begins with a digit 5 which is not allowed.

 

No special character, except underscore ( _ ), is allowed for defining name of program element. For example: if we define a name: roll, it will be considered wrong and compiler will show an error because we are using in the name which is a special character.

 

Two consecutive underscores are not allowed in the identifier name. For example:Identifier name roll__ no will be wrong because we use two consecutive underscores in the name which is not allowed in c programs.

 

In some C language compilers (Turbo C), length of identifiers is restricted to 31 characters. It means identifier name can have maximum 31 characters and minimum

 

1 character. If we use more than 31 characters in the name than it will not show any error, instead the compiler considers only first 31 characters as identifier name and ignore the remaining characters.Keywords cannot be used as identifier names. For example: int cannot be used for defining identifier name because it is a keyword and has a special meaning.

 

Identifier names are case-sensitive. It means identifier names in lower-case and

upper-case are considered distinct. So, we should take care of lower and upper cases while defining names. For example: roll and ROLL will be considered two different identifiers in C programs.

 

Blank spaces in the identifier names are not allowed. For example: identifier name roll no will be wrong because it contains a blank space between the wards roll and no.

 

7.7.3 Literals

Literals are also called constant values. These are the fixed values that are normally assigned to variables in the C-programs. These fixed or constant values can be categorized into two categories: Numeric and Character constant values as shown in the following diagram with suitable examples:

 


7.7.3.1 Numeric Literals : These are the numeric values, which can be used for numeric calculations. There are two types of numeric literals:

 

Integer Literals : These are literals without fractional(decimal) part. It consists of digits from 0 to 9 along with positive (+) or negative (-) sign. If number does not have any sign, it is considered the positive integer literal. For example: 56, +26, -96 etc. are

the integer literals.

 

Real Literals : These are literals with fractional(decimal) part. It consists of digits from 0 to 9 along with positive (+) or negative (-) sign. It also has a decimal point (.)which separates the integral and fractional part of the real number. If integral part does not have any sign, it is considered the positive real literal. For example: 3.14,+256.5896, -96.14. 36.00 etc. are the real literals.

 

7.7.3.2 Character Literals : These are the character values, which usually do not involve in the calculations. There are two types of character literals:

Single Character Literals ; These are the literals which have a single character enclosed in the single quotes. More than one printable character is not allowed in these literals. Non-printable characters also come in this category of constant literals though two symbols are used in these characters, for example: new line character (\n - backslash and a letter n), but yet they are considered to be a single character.Examples of single character literals are: ‘A’, ‘g', ‘7’, ‘+’, '$', Sn’, \t' etc. Values ‘AB', '45’are the invalid examples of single character literals because more than one character is enclosed in single quotes which are not allowed in the single character constant.

 

String Literals : These are the literals which have one or more characters enclosed in the double quotes. These literals may have the combination of letters, digits, special symbols, and blank space. Examples of these literals are: “V. Kansal", "A",“House#196", "1829" etc.

 

7.7.4 Operators

Operators are the symbols which are used to perform some mathematical or logical

operation. Operators are used to manipulate values/variables in the program. These values/variables are called operands. C supports a rich set of built-in operators. All these operators can be classified into three broad categories: unary, binary, and temary. A detailed explanation has been given on operators in the next chapter of this book.

 

7.7.5 Special Symbols

These are the symbols used as  punctuation marks. Each symbol has its different speciality in program. Each symbol is used to denote something special in the program. For example:semicolon (;) is used to terminate the statement, comma (,) is used as a separator, parenthesis

() are used to represent the functions, square brackets [ ] are used to denote arrays, Braces { }are used for grouping the statements etc.

 

7.8 VARIABLES AND CONSTANTS

These both are the important program elements which are used to store values in the program. Both are given a name and type of value to be stored in them. But there is a little difference between them. Variables allow us to change their values during execution time while constant do not. It means constants have fixed values while variables can have changeable values during program execution. C is a strictly typed language. It means we must declare variables and constants before using them in the program. If we use variables or constants without declaring them, compiler will generate a syntax error: "Variable not declared". So,each variable or constant must be declared in the program. Following are the syntax rules for declaring variables and constants in the program:

 

Syntax of variable declaration:

data type variable name;Here, data type tells the compiler what type of value is going to be stored in the variable,and variable mame is the valid identifier which tells the compiler about the name of the variable which will be used to refer to the value stored in the variable. Consider the following

example of variable declaration:

int roll no;

 

Here, int represents the integer data type while roll no is the identifier name which is used to refer to the variable. It means the variable roll no can hold only the integer values. It is not given any value, so a garbage value will be stored in it by default. If we want to assign it a value during its declaration, then it will be called variable initialization.For example:

int roll no=5;

 

This assigned value can be changed later at any time because a variable allows us to change its values at any time during execution.Syntax of constant declaration:A variable can be made constant if we put a keyword const before the variable declaration and assign it a fixed value at the time of declaration. Consider the following syntax rule:

 

const data type constant name = value;

Here, const is a keyword which tells the compiler that the given value cannot be changed during program execution. Consider the following example of defining constant:const float pi=3.14;

 

In this example, we define a constant value 3.14 which is of real type. It is given a name pi. The keyword float tells that the value will be of real type and const make it a fixed value that

cannot be changed during execution time. If we try to change its value, compiler will generate a compile error.

 

7.9 DATA TYPES

Data type defines which type of data will be stored in the program elements, such as variables, constant, arrays etc. Data types define a specific type or range of values for the variables or other program elements. C is a strongly typed language therefore data type of all the variables must be declared during declaration time.C supports many different types of data, each of which may be represented differently within the computer's memory. Storage representation of data in memory varies from machine to machine and compiler to compiler. For example: in Turbo C, int data type takes 2 bytes of memory while in Code::Blocks it takes 4 bytes of memory. Following table shows the list of primitive or basic data types available in the Standard C language:

 


7.10 HEADER FILES IN C

C provides a huge library of predefined functions to perform various types of tasks in the programs. All these functions are called library functions. To organize these functions, all the functions are logically grouped into separate files. These files are termed as header files. All the header files have .h extension. To use any of these functions in our program, we have to include these header files in our program. This inclusion is done by using the pre-processor directive include. In C, pre-processors begin with the symbol. Consider the following example:

 

In this example, stdio.h is a header file and #include is a pre-processor directive. Using this example, we can use any of the function defined in the stdio.h header file in our program.

There are many header files in C. The header files that will be used in a program, depends solely on our requirement in the program. Following are some of the common header files that

are used in the C programs:

 

The beader file stdio.b : The full name of this header file is standard input output header file. This file contains the functions that can be used for input and output from the standard input/output devices. For Example: scanf( } and printf() functions

 

The beader file conio.h : The full name of this header file is console input output header file. Console is screen where our program executes. This file contains the functions that are used for console during input/output. For example: clrscr( } and getch( ) functions

 

The header file math.h : This file contains mathematical and trigonometric functions that we can use in our programs for various mathematical operations. For example:

sqrt( ), pow( ), sin), cos() etc.

 

The header file string.b : This file contains functions that can be used for string manipulation operations. For example: strlen( ), strepy( ), strupr( ), strlwr( ), stremp(} etc.

 

To use any library function, we must use respective header file with pre-processor directive include in our program.

 

7.11 INPUT AND OUTPUT STATEMENTS IN C

Input and Output statements provide interaction between program and users. Using input statements, user provides input to program and using output statements output is displayed by

the program to user.All the input and output operations in C program are carried out using pre-defined functions. Although, there are many formatted and unformatted input/output functions provided by the C library, but normally, this input/output operation is carried out using scanf( ) and print f( ) formatted functions in C programs. Consider the following diagram which shows the purpose of input and output statements in the programs:



Now, we shall discuss these two commonly used input and output library functions in c programs, ie. scanf( ) and printf() function:

 

The scanf( ) function:Input data can be entered into the program from a standard input device by using C library function scanf( ). This function can be used to enter any combination of numerical values,single characters and strings. The general syntax for using functions is as follows:scanf("format string", &arg1, &arg2, ........, &argn);

 

Here, format string refers to a string that contains certain format codes depending on the data type of arguments, and arg], arg2, ........, argm ate the arguments that represent the

individual input data items. Normally, arguments are the variables preceded by address operator &. This address operator & specify the address of the variable where the data will be stored.

Format string and all the arguments must be separated by the comma operator. To have better understanding of the concept, consider the following example:

int a;float b;scanf("%d%f" ,dca,&b);

 

Here, "%d%f" is a format string which specify the type of value to receive from the keyboard. The format string %d is used to input the integer value for variable a, and %f is used to input float value for variable b. Here, a, and b are the two arguments representing variables which are getting values from user, The symbol & before these variables a, and b specifies that

the integer and float values will be stored at the memory addresses allotted to a, and b.

 

The printf( ) function : The printf( } function is used to display information on the monitor in C programs. This fimction is normally used to display simple text messages on the monitor (output) screen. The general syntax of this function for displaying simple text is as follows:

 

printf("simple text message");

For example:printf("Hello from C Language");This function can also be used to show any numerical, single character and string values stored in variables on the monitor (output) screen. The general syntax for displaying values stored in the variables is as follows:printf("format string", arg1, arg2, ........, argn);

 

Here, format string refers to a string that contains certain format codes depending on the data type of arguments, and argl, arg2, ......... argn are the arguments that represent the

individual output data items. Here, the printf( ) functions read values of arguments from memory and display them on the monitor screen. Format string and all the arguments must be separated by the comma operator. To have better understanding of the concept, consider the following example:

 

Here, "%d%f" is a format string which specify the type of value to display at the monitor screen. The format string %d is used to display the integer value stored in variable a, and %f is



used to display float value stored in variable b, Here, a, and b are the two arguments representing variables which are displaying values to user at monitor screen.

 

Figure 7.8 tries to illustrates the concept of working with scanf() and printf() functions in C programs:

Functions scanf() and printf() are the most important and useful functions that are widely used in any C program. These functions are part of the stdio.h header file. So, the header file stdio.h should be used in each ¢ program.

 

7.12 STRUCTURE OF C PROGRAM

As we know that a program is a set of instructions written for specific task. Logical grouping of instructions in a program is called a function or block. Hach C program is a collection of one or more functions and one of them should be named as main. It is because the

function main is the entry point of execution for a C program. It means a computer system starts execution of ¢ program from the main function.

Till now, we have discussed many

concepts of learning any programming

languages. Now, we have a clear  understanding about what is the character-set, different types of tokens, different types of data, input and output statements, and header files. All these concepts are essential to begin programming using c language. Now, we need to know the basic structure of c program where we can put all these stuffs to make simple program. In general, a simple executable C-program can have the structure as shown in figure 7.9.

 

Although we have discussed many of

concepts used in the above structure, yet again Wwe are going to have a brief discussion of all element of above program-structure:

 


Pre-processor Directive Statements : The pre-processor statement begins with

symbol, These statements instruct the compiler to perform some operations before compilation. Common use of these directive statements is to include header files or to define symbolic constants etc. Some of the common pre-processor examples are:

 

Global Declarations : Program elements in these declarations can be used throughout the whole program. These declarations can be variables, functions or any other program element. These declarations are written outside the body of the functions,

 

The main ( ) function : Execution of C program starts with main ( ) function. C

program cannot run without the main function. Every executable C program must contain one main ( ) function.

 

Braces { } ; Braces are used to define the block of statements. The left braces after main( ) indicates the beginning of the main function and the right braces indicates the end of the main function.

 

Local Declarations : Declarations inside any function are called local declarations.These declarations can be used only within the function in which they are declared.

 

Program statements : These statements are the instructions of program. They are used to perform a specific task. Each executable statement should be terminated with semicolon.

 

User defined functions ; A function is a logical grouping of statements to perform some specific task. Like main( ) function, we can define more functions according to our requirements. Because these functions are written by the user, therefore these are called user defined functions.

 

Now let us start C programming by making small C programs using whatever we have

learnt in this chapter. Before proceeding, we are assuming that you have downloaded and installed the Turbo C or Code::Blocks for C program. Now, we will proceed with how to develop and execute C programs using Code::Blocks:

 

1. Open Code::Blocks by double clicking on its icon on the Desktop.

 

2. Create a New file by Click on File  New Empty File or Using shortcut key

 

3. Now type the following program in the file, as shown in the following figure:

 


4, After typing the source code of the program, save it by clicking the File — Save File or by pressing shortcut key Ctrl+S. While saving the file, don't forget to write the file extension .c with the file name, for example: testl.c, where test1 is the file name and is the extension name for the C programs.

 

5. Now, we have to compile and execute this program by clicking on Build — Build and Run or by pressing shortcut key F9 from the keyboard.

 

6. If the program contains errors, they will be shown in the Logs and Others window which is present at the bottom of this window. If this window is not showing in the interface, we can show it by clicking on View —> Logs or by pressing shortcut key F2 from the keyboard. All the errors must be corrected to compile and execute the

program. Consider the following program having error at line 5:



In the above figure, red box in the 5th line shows that there is some error in this line.

Details of the errors can be seen in the "Build Messages" tab of "Logs and Others”window. All these errors must be removed for proceeding with compilation and execution.

 

7. When no errors left in the program, it will display the output of the program as shown below:



This output window will also display the time taken to execute the program. Now, to come back to the source code, press any key from the keyboard.By following the above mentioned steps, we can develop, compile and execute C programs in the Code::Blocks. Following are some more examples of C programs. These programs show the usage of various concepts that has been explained in this chapter.

 


In this program (Program 7.3), we have used many types of tokens. Let us discuss these tokens to illustrate whatever we have read in this chapter.

All Tokens in program : stdio.h void main () { int a= 47; float

 

Keywords : void, int, float(representing data types)

 

Identifiers :  stdio (name of header file), main, printf (name of functions),

a, pi (name of variables)

 

Literals : 47, 3.14 (fixed values)

Operators : = (assignment operator for storing values)

 

Special Symbols >

Now we are going to explain the whole program (Program 7.3) line by line so that we have a better understanding of programming:

 

Inline lof the program, we used pre-processor directive to include header file stdio.h in our program so that we can use printf( } function in our program.

 

In line 2, we started the mainQ function. Our program starts execution from this main( ) function. Any executable program must have the main function. We cannot define more than one main function in a c program.

 

In line 3, we used opening brace { which shows the beginning of main() function.

Inline 4 and 5, we declared integer and float type variables: int a; and float pi; and assigned them literal values. These declaration statements are terminated with special symbol semicolon

 

In line 6 and 7, we used output statement printf( ) function to show the values of integer and float variables a and pi, respective format strings %d and %f are used to represent the values.

 

In line 8, we use closing brace } which represents the end of the main function.

In the line 4 and 5 of above program, we use a special symbol // to explain the code in the program. The lines beginning with // are called Comments. Comments are used to describe our code in the program. They are ignored by compiler during compilation process. The symbol

// is used for single line comment. For multiline comments, we can use /* and */ symbols in our program.




 

If we use Turbo C for programming, then output window will not be display directly after compiling and executing the program. To view the output window, press Alt+F5 or open Windows menu and then click User Screen to view the output window. But if we use

code::blocks for c programming, then output window will automatically appears on our screen after successful execution of the program.

 

1. Cis a general purpose programming language which is developed by Dennis Ritchie.

 

2. Cis specially designated as a Middle Level language because it has the capabilities of both low and high level languages.

 

3. IDE is an Integrated Development Environment that provides an environment for writing programs along with tools for compiling, executing, testing and debugging programs.

 

4. Character set is a set of all allowed characters for making a program.

 

5. Tokens are smallest individual units in a program. They are like words and punctuation marks in English.

 

6. Keywords are the reserve words whose meaning are predefined in the C compiler.

 

7. Identifiers are the names given to program elements such as variables, arrays, fimctions ete.

 

8. Operators are the symbols which are used to perform some mathematical or logical operation.

 

9. Constants do not allow us to change their value during execution time while the value of variables can be changed.

 

10. Data types define a specific type or range of values for the variables or other program elements that can hold values in the memory.

 

11. The functions scanf( ) and printf( ) are formatted Input/output functions which can be used to deal with any combination of numerical values, single characters and strings.

 

12. Comments are used to describe our code in the program.

 

Part-A

1. Multiple Choice Questions

 

1 Cisa__._______ purpose programming language.

a. special

b. general

c. objective

d. None of these

 

2. Which of the following is invalid example of identifier?

a. roll no

b. %age marks

c.  rollno

d.s main

 

3. Which of the followings are the tokens?

a keywords

b. special symbols

c. Literals

d. All of these

 

4. Which of the following keywords do not represent a data type?

a. int

b. float

c. const

d. char

 

5. are used to describe a code in the program?

a. Compiler

b. Comments

c. Literals

d. Identifiers

 

2. Fill in the Blanks;

1 are the smallest individual units of a program.

2. The names given to program elements, such as variables, constants, arrays, functions ete. are called

3. Those program elements which do not allow changing their value during execution arecalled

4. To work with single precision values, we use__._ dia type.

5. File extension of header files is

 

3. Write the Full form of following:

1. FORTRAN

2. BCPL

3. IDE

4. stdio.h

5. conio.h

6. ASCII

 

Part-B

4. Short Answer Type Questions. (Write the answers in 4-5 lines)

 

1 Why C is called Middle Level Programming Language?

2. What is a character set?

3. What are keywords?

4. What should be the steps for creating and executing C program?

5. Write the difference between variables and constants.

6. What are Pre-processor directives?

 

Part-C

5. Long Answer Type Questions. (Write the answers in 10-15 lines)

 

1 What are Identifiers? Write the naming rules of identifiers.

2. What are Tokens? What are the different categories of tokens that can be used in a program?

3. What are the data types? Which primitive data types are supported by C language?

4. Explain the formatted input and output statements used in the C programs.