Sie sind auf Seite 1von 8

What is Programming Language?

A Programming Language is a formal language used to write instructions for the computer. It lets the
programmer express data processing in a symbolic manner without regard to machine-specific details.
Programming languages can be used to create programs that control the behavior of a machine and/or to
express algorithms precisely.
What is the generation of programming language? Describe it briefly.
Programming languages have been classified into several programming language generations.
Historically, this classification was used to indicate increasing power of programming styles. the
generations are described in brief:
1GL: The first generation program language is pure machine code, which is called machine language.
Machine languages are the only languages understood by computers. Every CPU has its own unique
machine language. While easily understood by computers, machine languages are almost impossible for
humans to use because they contain just ones and zeros. There is no need to translate the code and it will
run straight away. The main drawbacks of machine language that the code cannot be ported to other
systems and has to be rewritten, code is difficult to edit and update.
2GL: The second-generation program language is assembly language. Assembly languages are similar to
machine languages, but they are much easier to program in because the instructions
and variables have names instead of being just numbers. To compile the assembly code into machine
code, we need an assembler which translates the whole code. Examples of assembly languages are:
MASM (Microsoft Macro Assembler), BAL (Basic Assembler) etc. The main problem of assembly language
is that it requires extensive knowledge of programming and consumes a lot of time when writing a big
program. The program codes are not also machined independent.
3GL: The third-generation language is called high-level" programming language. Third-
generation programming languages brought many programmer-friendly features to code such as loops,
conditionals, classes etc. This means that one line of third generation code can produce many lines of
object (machine) code, saving a lot of time when writing programs. Third generation languages can be
platform independent, meaning that code written for one system will work on another. To convert a 3rd
generation program into machine language requires a Compiler or an Interpreter. . Examples of assembly
languages are: FORTRAN, COBOL etc.
4GL: The fourth-generation language is designed to be closer to natural human language than other high-
level languages. They are accessible to people without formal training as programmers. They allow
multiple common operations to be performed with a single programmer-entered command. They are
intended to be easier for users. All 4GLs are designed to reduce programming effort, the time it takes to
develop software, and the cost of software development. Some 4G languages are: FoxPro, LINC, FOCUS
etc. 4G languages also use Complier or an Interpreter to translate the language into machine code. For
example, a typical 4GL command is: FIND ALL RECORDS WHERE NAME IS "SMITH"

What is a Translator?
Translator is defined as a computer program that converts instructions written in one language another
without changing the initial logic in terms of computer language. Other language translators convert
source code into a format that can be understood by the computer processor. Assemblers, interpreters
and compilers are examples of computer language translators.

What is an Assembler?

An assembler is a program that takes basic computer instructions and converts them into a pattern
of bits that the computer's processor can use to perform its basic operations. The assembler program
takes each program statement in the source program and generates a corresponding bit stream or
pattern (a series of 0's and 1's of a given length). The output of the assembler program is called the object
code or object program relative to the input source program. The sequence of 0's and 1's that constitute
the object program is sometimes called machine code.
What is a Compiler?
A compiler is a computer language translator that translates the high level language into machine
language. When a user writes a code in a high level language such as Java and wants it to execute, a
specific compiler which is designed for Java is used before it will be executed. The compiler scans the
entire program first and then translates it into machine code which will be executed by the computer
processor and the corresponding tasks will be performed.

Shown in the figure is basic outline of the compilation process, here program written in higher level
language is known as source program and the converted one is called object program.
What is an Interpreter?
Interpreters are not much different than compilers. They also convert the high level language into
machine readable binary equivalents. Each time when an interpreter gets a high level language code to be
executed, it converts the code into an intermediate code before converting it into the machine code. Each
part of the code is interpreted and then execute separately in a sequence and an error is found in a part of
the code it will stop the interpretation of the code without translating the next set of the codes.

Outlining the basic working of the interpreter the above figure shows that first a source code is converted
to an intermediate form and then that is executed by the interpreter.

Difference between compiler and interpreter
No Compiler

Interpreter
1 Compiler takes entire program as input. Interpreter takes single instruction as input.
2 Intermediate object code is generated. No intermediate object code is generated.
3 Conditional control statements execute faster. Conditional control statements execute slower.
4 More memory requirement since object code is
generated.
Memory requirement is less since no object
code is generated
5 Program need not to be compiled every time
when using compiler.
Every time higher level program is converted
into machine language when program is
interpreted.
6 Compiler generates the error report after
translation of the entire program. When the
errors are checked, compiler again translates
the entire program.
Interpreter stops the translation after getting
the first error and continue the translation
process after the error is checked.
7 Compiler takes a larger amount of time
compare to interpreter to translate.
Interpreter takes lesser time to translate in the
same process.
8 Example: C Compiler Example: Basic

What is Keyword? Give example.
Keywords are words that are reserved by a program. Keywords have special meanings and these
meanings cannot be changed. Every programming language has a set of keywords that cannot be used
as variable names. For example: int money; (here int is a keyword that indicates money is of type
integers). Keywords are sometimes called reserved names. Keywords serve as basic building blocks for
programming statements. All keywords must be written in lowercase. Below are some examples of
keywords which are used in C Programming: long, case, char, const, goto, double, else, for, while, int, void,
if, do.
What are identifiers? What are the rules for declaring identifiers? Give example.
In C programming, identifiers are names given to C entities such as variables, functions, structures, arrays
etc. Identifiers are created to give unique name to C entities to identify it during the execution of
program. These are user defined names and consist of a sequence of letters and digits. Both uppercase
and lowercase letters are permitted, although lowercase letters are commonly used. The underscore
character is considered as a letter in identifiers. It is usually used in the middle of an identifier. For
example: int mango_tree; (here mango_tree is an identifier which denotes an integer variable by the int
keyword.
Rules for writing identifier:
1. An identifier can be composed of letters (both uppercase and lowercase letters), digits and
underscore '_' only.
2. First character of the identifier must be a letter or underscore. But, it is discouraged to start an
identifier name with an underscore though it is legal. Because identifier that starts with
underscore can conflict with system names.
3. Only first 31 characters are significant
4. No keyword can be used as identifier
5. Must not contain any white space and special symbols like !,@,#,?, $ etc.
6. Uppercase and lowercase letters are distinct for declaring identifiers. For example: the identifier
mango is not the same as MANGO or Mango. Here system will consider them 3 different
identifiers.
7. Identifiers must not begin with a digit. For example: 11abc is not a valid identifier because it
started with digits.
What is constant? Describe its classification with example.
Constants in C refer to fixed values that do not change during the execution of a program. C supports
several types of constants. The two main types of constants are:
a. Numeric constant:
1. Integer constants: Integer constant refers to a sequence of digits. there are 3 types of integers:
Decimal: Decimal integers consist of any combination of digits from 0 to 9, preceded by an
optional + or sign. For examples: 123, -321, 0, +78
Octal: Octal integers consist of any combination of digits from 0 to 7, with a leading 0. For
examples: 037, 0, 0435
Hexadecimal: hexadecimal integers consist of any combination of digits 0 to 9 along with
A to F, with a leading 0x. The letters A to F represent the numbers 10 through 15. For
example: 0x2, 0x9F.
2. Real constants: Real constants refer to fractional numbers which have a decimal point. Integer
constants are inadequate to represent quantities that vary continuously. These quantities are
represented by numbers containing fractional parts like 26.082. for example: .95, -0.75 etc.
Embedded spaces, commas, and non-digit characters are not permitted between digits. For example:
15 720, 20,000, $1000 are all invalid integers.
b. Character constant:
1. Single character constants: A single character constant contains a single character. That character
may be an alphabet or a digit or a special symbol, enclosed in a single quote. For example: 5 , X ,
$ etc.
2. String constants: a string constant is a sequence of characters enclosed in double quotes. The
characters may be alphabets, numbers, blank spaces, special symbol or a combination of them. For
example: Hello ! , 5+3, @!#$ etc.
What is a variable? What are the rules for declaring variables? Give examples of valid and invalid
variables.
Variables are used to store data value and that values can be change during the execution of the program.
Unlike constants that remain unchanged during the execution of a program, a variable may take different
values at different times during the execution of a program.
Rules for declaring variables:
1. A variable can be composed of letters (both uppercase and lowercase letters), digits and
underscore '_' only.
2. First character of the variable must be a letter or underscore. But, it is discouraged to start an
variable name with an underscore though it is legal. Because identifier that starts with underscore
can conflict with system names.
3. ANSI standard recognizes a length of 31 characters of the variables. However, length should not be
normally more than eight characters, since only the first 8 characters are treated as significant by
many compilers.
4. No keyword can be used as variable.
5. Variables must not contain any white space and special symbols like !,@,#,?, $ etc.
6. Uppercase and lowercase letters are distinct for declaring variables. For example: the variable
mango is not the same as MANGO or Mango. Here system will consider them as 3 different
variables.
7. Variables must not begin with a digit. For example: 11abc is not a valid identifier because it
started with digits.
Some examples of invalid variables
variable name remarks
char char is a keyword
price$ dollar sign is not allowed
(area) () is not allowed
25th must not begin with a digit
end end is a keyword
x! factorial sign is not allowed
ok-name - sing is not allowed
my variable blank space is not allowed

What is C token? Describe each type of them.
In a C program, the smallest individual units are known as C tokens. C has six types of tokens. Programs
are written using these tokens and the syntax of the language.
Keywords: Keywords are words that are reserved by a program. Keywords have special meanings
and these meanings cannot be changed. For example: int money; (here int is a keyword that
indicates money is of type integers). All keywords must be written in lowercase. Some examples
of keywords which are used in C Programming: long, case, char, const, goto, double, else etc.

Identifiers: In C programming, identifiers are names given to C entities such as variables,
functions, structures, arrays etc. These are user defined names and consist of a combination of
letters and digits. Both uppercase and lowercase letters are permitted but no special symbols
other than underscore can be used as identifiers. For example: int mango_tree; (here mango_tree
is an identifier which denotes an integer variable by the int keyword.

Constants: Constants refer to fixed values that do not change during the execution of a program. C
supports integer constants such as decimal, octal and hexadecimal integers (-75, 0xA1, 01124). It
also supports fractional numbers which are real constants (-123.55, 0.95, .32). There are also
single character constants contains only a single character enclosed in a single quote (x, 5) .

Strings: String is a constant which contains sequence of characters enclosed in double quotes. The
characters may be alphabets, numbers, blank spaces, special symbol or a combination of them. For
example: Hello ! , 5+3, @!#$ etc.

Operators: Operators are symbols that represent a specific mathematical or logical action. C
language is rich in built-in operators and provides the following types of operators: Arithmetic
variable name remarks
first_tag valid characters are used
int_type keyword is a part of name
x111 digits at end
average first 7 characters are significant
Delhi valid characters are used
x_factorial valid characters are used
_okname underscore is used first
room4 valid characters are used
Some examples of valid variables
Operators, Relational Operators, Logical Operators, Bitwise Operators, Assignment Operators,
Increment and decrement Operators, Special operators, Conditional operators.

Special symbols and punctuators: Symbols other than the digits, operators, alphabets and blank
spaces are special symbols and punctuators. The punctuation and special symbols in the C
character set have various uses, from organizing program text to defining the tasks that the
compiler or the compiled program carries out. They do not specify an operation to be performed.
Some punctuation symbols are also operators. For example: @,#,$,!(special symbols) where ( ),[ ],
{ }, . , /(punctuators).
What is type casting or type conversion or coercion? Classify it with examples.
Type Casting is a method using which a variable of one data type is converted to another data type. For
example, if we want to store a long value into a simple integer then we can type cast long to int.
Implicit type conversion: C automatically converts any intermediate values to
the proper type so that the expression can be evaluated without losing any
significance. This automatic type conversion by the C compiler is called implicit
type conversion, also known as coercion. C uses the rule that, in all expressions
except assignments, any implicit type conversions are made from a lower size type
to a higher size type. If the operands are of different types, the lower type is
automatically converted to the higher type before the operation proceeds. The
result is of the higher type. For example:
1. short a=2000;
2. int b;
3. b=a;
Explicit type conversion: In programming, there are some instances when we want to force a type
conversion in a way that is different from the automatic conversion. For example, when calculating the
ratio of females to males in a town:
ratio= female_number/ male_number
Since female_number and male_number has been decalared as integers in the program, the fractional
part of the result of the division would be lost and the ratio would represent a wrong result. This problem
can be solved if we simply put the type of variable we want the actual variable to act as inside
parentheses ( ) in front of the actual variable:
ratio= (float) female_number/male_number

The operator (float) converts the female_number to floating point and using the rule of automatic
conversion, the division is performed in the floating point mode, thus retaining the fractional part of the
result. This process of forced conversion is called as explicit conversion.

What is data type? Classify it with examples.

A data type defines which kind of data will store in variables and also defines memory storage of data. C
supports 3 classes of data types:
long double
double
float
unsigned long int
long int
unsigned int
int
short char
(Here the value of a has been promoted from short to int and
we have not had to specify any type casting operator. This is
known as implicit conversion. )
1. Primary/Fundamental/ Standard data types: All C compilers support five fundamental data
types:
Integer (int): Integers are whole numbers which do not have any fractional part and decimal
point. C has 3 classes of integer storage, namely short int, int and long int in both signed and
unsigned forms. Size and range of different integers are:
type size(bits) range
int 16 -32,768 to 32767
unsigned int 16 0 to 65535
short int 8 -128 to 127
unsigned short int 8 0 to 255
long int 32 2,147,483,648 to 2,147,483,647
unsigned long int 32 0 to 4,294,967,295

Floating point (float): Floating point are integers which contain fractional part. They are
defined in C by the keyword float. Floating point numbers are stored in 32 bits, with 6 digits of
precision.

Double-precision floating point (double): When the accuracy provided by a floating number
is not sufficient, the type double can be used to define the number more precisely. it requires
64 bits memory space and provides a precision of 14 digits.
type size(bits) range
float 32 3.4E-38 to 3.4E+38
double 64 1.7E-308 to 1.7E+308
long double 80 3.4E-4932 to 3.4E+4932

Character (char): Character data type is used to represent letters and symbols. They are
defined in C by the keyword char. One single character takes 8 bits of internal storage. the
qualifier signed or unsigned may be explicitly applied to character.
type size(bits) range
char or signed char 8 -128 to 127
unsigned char 8 0 to 255

Void type (void): The void type of pointer is a special type of pointer. In C, void type has no
value, so void pointers are pointers that point to a value that has no type. This allows void
pointers to point to any data type, from an integer value or a float to a string of characters.

2. Derived data types: Data types that are derived from fundamental data types are called derived
data types. Derived data types don't create a new data type but, instead they add some
functionality to the basic data types. The derived data types are:
Array types: An array is a collection of related data elements of same type. They are stored in
contagious memory allocation. For example, an array can be used to represent a list of numbers
(int) or a list of names (char).
Pointer types: A pointer is a special variable that holds a memory address (location in
memory) of its each value.
Structure types: Structure is a collection of variables of different data types. Unlike array, the
structure data types support logically related data items of different types under a single name.
For example: we can declare city as a structure where the attributes might be name (char),
country (char), population (float) etc.
Union types: Unions are a concept borrowed from structures and therefore have the same
characteristics like structures. But the major distinction between them- in structures, each
member has its own storage location, whereas all the members of a union use the same
location. This implies that, although a union may contain many members of different types, it
can handle only one member at a time.

3. User defined data types: In C, we can define our own data types based on other existing data
types. We can do this using the keyword typedef, whose format is:

typedef existing_type new_type ;
where existing_type is a C fundamental or compound type and new_type is the name for the new
type we are defining. For example:

typedef int units;
typedef float marks;

In this case we have defined two data types: units and marks as int and float respectively, that
can be used later to declare other valid types. For example:

units batch1, batch2;
marks name1[50], name2[50]

Here, batch1 and batch2 are declared as int data types and name1[50] and name2[50] are
declared as 50 element floating point array type. Actually typedef does not create different
types. It only creates synonyms of existing types.

Das könnte Ihnen auch gefallen