Programming Flashcards

1
Q

What is Language Translation?

A

Language translation is the process of converting high-level instructions to machine-level instructions (0 and 1) without sacrificing the code’s functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List the stages of language translation/compilation

A

Lexical analysis

Syntax analysis

Semantic analysis

Intermediate code generation

Code generation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the lexical analysis stage of language translation/compilation

A

At this stage of the process the following is done:

All comments and unnecessary spaces are removed and some simple error checking is performed. For example, if a language has restrictions on the length of an identifier this analyzer will determine if the variable is too long.

Program instructions are scanned and actual symbols of the program such as integers, identifiers, reserved words are created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the syntax analysis stage of language translation/compilation

A

This is the process of determining whether the syntax of the program is correct.

The code is checked to see if they follow the rules of a particular programming language were followed.

NOTE: The syntax rules of a language define how a programmer can put symbols, reserved words and identifiers together to make a valid program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the semantic analysis stage of language translation/compilation

A

Semantic analysis is concerned with the meaning or interpretation of codes/commands in the context in which they are used. During this stage, the commands in the program are tested to see if they were correctly used based on the language.

The constructs of the program is check for semantic correctness and the necessary information stored in a construct symbol table.

The semantics of a program statement define what that statement means (its purpose in a program). A program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain intermediate code generation and code optimization

A

Codes are modified so that they can be executed faster. This reduces the execution time for a program by looking at how the codes could execute more efficiently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain the Code Generation stage of language translation/ compilation

A

At this stage the actual machine codes or assembly language are generated from the internal source program. It is the most detailed part of the compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are comments written in C?

A

Single line comments are written with two slashes
e.g:
// This is a comment

Multi Line comments are written using slashes and asteriks
e.g:
/* This is a comment */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How are if then statements written in C?

A

Syntax/ Layout :
if (condition)
{
Action to be taken if condition is true
} // End of if statement

E.g
if(grade>60)
{
printf(“pass”);
}// end of if statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are if else statements written in C

A

if(condition)

{

Action(s) to be taken if condition is true

}

else

{

Action(s) to be taken if condition is false

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a syntax error/ when does it occur?

A

A syntax error occurs when the compiler cannot recognize a statement because it vio-
lates the language rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

C programs typically go through six phases to be executed, these are:

A
  1. edit
  2. preprocess
  3. compile
  4. link
  5. load
  6. execute.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are run time errors

A

Errors that occur as a program runs

E.g Division by Zero
Divide-by-zero is generally a fatal error that causes the
program to terminate immediately without successfully performing its job. Nonfatal
errors allow programs to run to completion, often producing incorrect results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define variables

A

//fig02_04.c
//Addition program
#include <stdio.h></stdio.h>

// function main begins program execution 
int main (void) {
int integer1 = 0; // will hold first number user enters
int integer2 = 0;// will hold second number user enters 

printf("Enter first integer: "); // prompt
scanf("%d", &integer1); // read an integer

printf("Enter second integer:"); // prompt
scanf("%d", &integer2); // read an integer

int sum = 0;// variable in which sum will be stored 
sum = integer1 + integer2;  // assign total to sum

printf("Sum is %d\n", sum); // print sum } // end function main
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define variables

A

//fig02_04.c
//Addition program
#include <stdio.h></stdio.h>

// function main begins program execution 
int main (void) {
int integer1 = 0; // will hold first number user enters
int integer2 = 0;// will hold second number user enters 

printf("Enter first integer: "); // prompt
scanf("%d", &integer1); // read an integer

printf("Enter second integer:"); // prompt
scanf("%d", &integer2); // read an integer

int sum = 0;// variable in which sum will be stored 
sum = integer1 + integer2;  // assign total to sum

printf("Sum is %d\n", sum); // print sum } // end function main
How well did you know this?
1
Not at all
2
3
4
5
Perfectly