PSEB 11th Computer Science -Eng Notes 2022-23 Chapter 7

 Chapter 7th

Introduction to C and Basic Structure of C Program Que1: Multiple Choice Questions

1.  C is a                                 purpose programming language.

a.  special                   b. general                             c. objective                           d. None of these

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

a.  roll_no                   b. %age_marks                   c. rollno                                d. 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 Que: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 etc. is called                  

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


4.      To work with single precision values, we use                             data type.

5.      File extension of header files is                               

Ans:     1. Token               2. Identifier                        3. Constant                       4. float                  5. .h

Que:3 Write the Full form of following:

1.      FORTRAN         Formula Translation

2.      BCPL                 Basic Combined Programming Language

3.      IDE                     Integrated Development Environment

4.      stdio.h                 Standard Input Output Header file

5.      conio.h                Console Input Output Header file

6.      ASCII                 American Standard Code for Information Interchange

Que:4 Short Answer Type Questions.

Q1: Why C is called Middle Level Programming Language?



Ans: C has the functionality of both types of programming languages, i.e. low-level and high-level programming languages. It means C language is suitable for writing both types of programs - system programs and application programs. Thus C-Language became a programming language that stood between both low-level and high-level programming languages. That is why C language is called middle level language. However, the middle level language is not a special category of programming languages. Because of the special capabilities of the C language, it is known as a middle level programming language.

Q2: What is a character set?

Ans: The set of all characters and symbols used in the C language is called the character set of C language. The C language supports the ASCII character set. The following characters and symbols can be used in C language:

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

         Digits (0 to 9)

         Special Symbols, For Example: ! @ # $ % ^ . ? / | \ etc.

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



Q3: What are keywords?

Ans: Keywords are also called Reserve Words. These words are predefined in C compiler. The meaning of these words is predefined. They are used for the specific purpose for which they were defined. We cannot change their meaning. In Turbo C these words are shown in white color while in Code::Blocks these words are shown in blue color. The standard C language has 32 keywords. For example: int, float, void, if, else, for, while etc. In C programming, all keywords are written in lowercase letters only.

Q4: What should be the steps for creating and executing C program? Ans: The following steps can be used to create a C language program:

1.      Develop a program algorithm.

2.      Create a C program as per the algorithm using any text editor or IDE that supports C language.

3.      Save the file by writing a file name with .c extension.

4.      Compile the program.

5.      If the program has a syntax error, correct it and repeat step 4.

6.      Execute the program.

7.      Output of program will appear in the output window. Q5: Write the difference between variables and constants.

Ans: Both of these are important program elements that are used to store a value in a program. Both elements are given a name in the program and the type of value to be stored in them. But there is a slight difference between the two. Variables allow us to change their values while running a program whereas constants do not allow it. It means constant values are fixed while variable values are changeable.

Q6: What are Pre-processor directives?

Ans: Pre-processor instructions are those statements that begin with the # symbol. These statements give instructions to the compiler to perform some specific operations before compilation. These directive statements are commonly used to include header files in the program or to define symbolic constants. Here are some examples of commonly used pre-processors:

#include <stdio.h> #define PI 3.14

Que:5 Long Answer Type Questions.

Q1: What are Identifiers? Write the naming rules of identifiers.

Ans: Identifiers are the names given to program elements, such as variables, constants, arrays, functions, structures, etc. Some rules are followed in C programs to define the names of program elements. These rules are as follows:

         The identifier must start with a letter or underscore (_) sign.

         No special symbols, except underscore (_), are allowed in the identifier.

         Two consecutive underscores cannot be used in the identifier.

         In Turbo C compiler, the length of the identifier is limited to 31 characters.

         Keywords cannot be used as identifier.

         Identifier are case-sensitive.

         No spaces are allowed in the identifier.

Q2: What are Tokens? What are the different categories of tokens that can be used in a program? Ans: Tokens are like words and punctuation marks used in English. A C program is made up of tokens. Tokens are the smallest individual units in a program. A C program can have the following five types of tokens:




1.      Keywords: These are predefined words. For example: int, float, char, if, else, void etc.

2.      Identifier: These are the names given to program elements. For example: main, printf, etc.

3.      Literals: These are fixed values. For example: 5, -25, 3.14, ‘A’ “Hello” etc.

4.      Operators: These are the symbols for specific operations. For example: +, -, *, /,>, <, = etc.

5.      Special symbols: These are the special symbols. For example: #, &, { }, ( ), [ ], :, ; etc. Q3: What are the data types? Which primitive data types are supported by C language?

Ans: Data type defines what type of data is to be stored in program elements, such as variables, constants, arrays, etc. They define a specific range of values for variables or other program elements. The C language supports a variety of data types. The following table shows the different basic data types available in the standard C language:

Keyword

Description

Memory Requirement

Range of values

Format

char

Used to store single

byte/character data

1 byte

-128 to 127

%c

int

Used to store integer type

data

2 bytes

-32768 to +32767

%d

float

Used to store single precision

floating values

4 bytes

3.4x10-38 to

3.4x10+38

%f

double

Used to store double

precision floating values

8 bytes

1.7x10-308 to

1.7x10+308

%lf

void

Used with functions which

do not return any value

-

-

-

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

Ans: Input and output statements provide interaction between users and programs. The user provides input to the program using the input statement and the program gives the output to the user using the output statement. C programs usually use the scanf () and printf () functions for formatted input/output operations. These functions are part of the stdio.h header file. That's why the header file stdio.h is included in every C program. The following figure illustrates the purpose of input and output statements in C programs:


Input function scanf (): In the C program, the scanf () function is used to receive data from a standard input device (i.e. keyboard). This function can be used to input any number, single character or string values. For example:

scanf (“%d %f”, &a, &b);

Output function printf (): In the C program, the printf () function is used to represent any information or value on the monitor (output) screen. for example:

printf ("Hello from C Language"); printf (“%d %f”, a, b);



No comments:

Post a Comment