Additional Questions

Unit no. 01: Introduction to Programming

Additional Question Answers:

  • Write down some applications of computers.

Some applications for computers are as follows:

Searching on the internet

Controlling and operating satellite and rocket launchers

Tracking inventory

Printing books

Landing airplanes

  • Define computer programming.

Computer program:

The process of feeding or storing instructions in the computer is known as computer programming.

  • What is the use of programming languages?

Use of programming languages:

Programming languages are the means of communication between the user and the computer. Computers cannot understand English Urdu or any other common language that humans use for interacting with each other.

They have their own special languages designed by computer scientists. Programmers write computer programs in special languages called programming languages. Java, C, C++, C#, Python are some of the most commonly used programming languages.

  • Define language translators.

Language translator:

A language translator is a system which is used to convert programs written in high level language into equivalent machine code. For example, a compiler, interpreter and assembler.

  • What is syntax error?

Syntax error:

While programming, if proper Syntax or rules of the programming language are not followed, the program does not get compiled in this case the compiler generates an error. This kind of errors are called syntax errors.

  • Write down the general structure of the include statement.

The general structure of an include statement:

# include<header_file_name>

Hair header file name can be the name of any header file.

What is the use of math.h header file?

Math.h header file contains all predefined mathematics functions.

  • How do we include header files in our program?

Including header files:

We include header files in our program by writing the includes statements at the top of program. For example,

# include<stdio.h>

  • Write down the types of comments in C language.

Types of comments in C language:

There are two types of comments in C language

Single line comments

Multiline comments

  • What is meant by character set of language?

Each language has a basic set of alphabets called characters at their combined in an allowable manner to form words and then these words can be used to form sentences.

  • Define constants. Also explain the types of constants.

Constant:

Constants are the values that cannot be changed by a program. For example, 5, 75.7, 15 etc.

Integer Constants:

These are the values without a decimal point e.g. 7, 1256, 301000, -54, -2256 etc. They can be positive or negative. If the value is not preceded by a sign, it is considered as positive.

Real Constants:

These are the values including a decimal point e.g. 3.14, 15.333, 75.04, -990.44 etc. They can also be positive or negative.

Character Constants:

Any single small case letter, upper case letter, digit, punctuation mark, special symbol, enclosed within ‘ ‘ is considered as character constant e.g. ‘5’, ‘88’, ‘a’, ‘A’, ‘!’ etc.

  • What is the use of integer constants?

These are the values without a decimal point for example 45, 7, 1345, 5409, 817.

  • Write down a program to demonstrate the declaration and initialisation of two variables.

Following example shows are a program that demonstrates the declaration and initialization of two variables.

# include <stdio.h>

Void main()

{

Char grade;

Int value=25;

grade = ‘B’;

}

  • When do we initialize the variable?

Initialization of variable:

The variable can be initialized at the time of declaration or after declaration.

  • What is meant by a variable declaration?

Variable declaration

I really must be declared before it’s used full stop variable declaration includes specifying variables data type and giving its available valid name.

  • Who is the programmer?

A person who knows how to write a computer program correctly is known as a programmer.

  • Can we be able to declare a variable without mentioning its data type?

A variable cannot be declared unless you mention its data type after declaring a variable its data type cannot be changed full stop declaring a variable specifies the type of variable the range of values allowed by that variable and the kind of operations that can be performed on it.

  • How can a variable be declared in a C program?

Variable declaration

Declaring a variable includes specifying its data type and giving it a valid name.

The following syntax can be followed to declare a variable.

data type_ variable _ name;

For example

Int age;

float height;

Int salary;

  • Is it possible to declare multiple variables in a single statement or in a single line?

Multiple variables of same data type can be declared in a single statement, as shown in the following example:

Int age, basic_salary, gross_salary:

  • How simple 9 is different from ‘9’?

A digit used as a character constant i-e. ‘9’, is different from a digit used as an integer constant i-e, 9. We can add two integer constants to get the obvious mathematical result e.g, 9+8=17, but we cannot add a character constant to get the obvious mathematical result e.g. ‘9’+8 ≠ 17.

  • Is the sequence of statements written in program C is important?

The sequence of statements in a C language program should be according to the sequence in which we want our program to be executed.

  • Is C a case sensitive language?

C language is case sensitive. It means that if a keyword is defined with all small case letters, we cannot capitalize any letter i-e. int is different from Int.

  • What is Statement terminator? OR How C statements are terminated?

Each statement ends with a ; semi colon symbol. This semi colon is known as Statement Terminator.

  • What is variable. Discuss the different Data types of a variable.

Variables

Available is actually a name given to a memory location as the data is physically stored inside the computer’s memory. The value of a variable can be changed in a program. It means that in a program if a variable contains value 5 then later we can give it another value that replaces the value 5.

Each variable has a unique name called identifier and has a data type. Data type describes the type of data that can be stored in a program. C language has different data types such as in float and char. The types in float and char are used to store integer real and character data respectively.

Data types of a variable:

Each variable in C language has a data type. The data type not only describe the type of data stored inside the variable but also the number of bytes that the compiler needs to reserve for data storage. In the following we discuss different data types provided by C language.

Integer_int (signed or unsigned)

Integer data type is used to store integer values whole numbers. Interior takes a four by its of memory. To declare a very able of type integer be used the keyword int.

Signed int:

Assigned in can store both positive and negative values. By default type int is considered as a signed integer.

Unsigned int:

And unsigned int can store only positive values and its value. Keyword unsigned int is used to declare an unsigned integer.

Floating point_ float

Flot data type is used to store a real number with floating point up to 6 digits of precision. To declare have variable of type float we use the keyword float. A float uses 4 bytes of memory.

Character_char

To declare character type variables in C, we use the keyword char. It takes up just one bite of memory for storage. Available of type char can store One character only.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top