• LOGIN
  • No products in the cart.

Updated ProC Interview Questions-2021

1.What is Pro*C?

Pro*C means creating a program that is embedded with SQL statements. We can access the Oracle database with the help of Pro*C. The C programming language provides the flexibility for data processing by manipulating or retrieving the data from the Oracle database. Therefore, we can say that Pro*C allows the C programming language to connect the C program with the Oracle database and do the manipulations according to our requirements.

2.Why Pro*C?

The following are some of the reasons why use have to use PreCompiler such as Pro*C.

•To use the power and flexibility of a high level language.

•To provide the required user interface

•To customize applications, which may not be possible with available tools. For example, there may be a report that cannot be generated using any of the available report writers.In such cases it is possible to use C to generate that report by taking data from Oracle database.

•To access Oracle data on one side and a particular hardware on the other side.

The above list is by no means complete. It is only to give you some idea about what can be done and not a comprehensive list of all possibilities.

3.What is the difference between C and Pro*C? 

Pro*C uses either C or C++ as its host language. During compilation, the embedded SQL statements are interpreted by a precompiler and replaced by C or C++ function calls to their respective SQL library. The output from the Pro*C precompiler is standard C or C++ code that is then compiled by any one of several C or C++ compilers into an executable.

4.Explain Concept of Pro*C briefly? What is the use of it? Tell about the syntax of Pro*C?

•The Pro*C compiler allows you to embed the SQL statements in the C program, and it also provides the required user interface.

•Unlike many other development tools, the Pro*C allows you to customize applications. It creates user interfaces that incorporate the latest windowing and mouse technology. Sometimes it is possible that we cannot generate the reports from other development tools, but we can achieve this by retrieving the data from the oracle database.

5. What processor directives and statements levels are used in Pro*C?

The preprocessor directives that Pro*C/C++ supports are: 

#define, is used to write macros for use by the precompiler and the C/C++ compiler.

•#include, is used to read other source files for use by the precompiler

•#ifdef, is used to precompile and compile source text conditionally, depending on the existence of a defined constant

•#ifndef, is used to exclude source text conditionally

•#endif, to end an #ifdef or #ifndef command

•#else, to select an alternative body of source text to be precompiled and compiled, in case an #ifdef or #ifndef condition is not satisfied

•#elif, is used to select an alternative body of source text to be precompiled and compiled, depending on the value of a constant or a macro argument.

6.What are the requirements of Pro*C?

The main requirement of Pro*C is to install the Pro*C software. When we are installing the Oracle database, then we have to make sure that we have selected the Pro*C components. If we have to check whether the installation of oracle contains the Pro*C components is by checking the PRECOMP directory of Oracle.

7. How can we compile the Pro*C program?

Oracle software provides the PROC compiler (Oracle Precompiler), and this compiler takes the C program having embedded SQL statements.

8.What is Oracle Precompiler?

An oracle precompiler is a programming tool that allows the user to embed the SQL statements in a high-level source program. This compiler takes the source program as input, replacing the embedded SQL statements with the oracle runtime library calls, and this modified program can now compile, link, and execute. The step by step process is mentioned below:

•First, we create a C program, which contains the SQL statements, and then we save this file with an extension ‘.PC’. Here, ‘.PC’ means that the program is a Pro*C program.

•After creating a program, we compile the program by using the PROC compiler, which is provided by the Oracle. The PROC compiler generates .c file with all the SQL statements replaced by the functions which are already pre-defined in the Oracle runtime library.

•The file created by the PROC compiler will be compiled again by the C compiler, which is supported by Pro*C. In Windows, the PROC compiler supports Microsoft Visual C++ compiler.

•The C compiler will create a .exe file.

•Now, finally, we run the .exe file.

9.What is Pro*C Syntax?

In the C program, all the SQL statements must start with EXEC SQL, and should end with the semicolon ;.We can write the SQL statement anywhere in the program but with one restriction that declarative statements should not come after the executable statements.

Suppose we want to retrieve the student marks from the database based on their id, then its program would be written as:

{   

int marks;  

EXEC SQL select marks INTO : marks from student where student_id=6;  

printf(“The marks of the student is : %d”, marks);  

}  

10.What is Embedded SQL statements in Pro*C?

Here, embedded SQL means placing the SQL statements inside the source program. As we house the statements inside the C program, so C program is also known as the host program, and the language we use is known as the host language. The Pro*C provides the ability to embed the SQL statements inside the program.

Embedded SQL statements are of two types:

•Executable statements

•Directives

11.What is meant by Executable statements?

Executable statements are the SQL statements that allow you to manipulate the data in the Oracle database. These statements call the Oracle runtime library. It also allows your program to connect to the Oracle database, to define the query, to manipulate the data, and process the transactions. These statements are written where C executable statements can be placed.

12.What is Directives?

Directives or declarative statements are the SQL statements that neither call the Oracle runtime libraries nor operate on the Oracle data. It is used to declare the Oracle objects, SQL objects. These statements can be written where the C variables can be declared.

13.What is Host Variables?

Host variables are the variables of the host language that are used with the SQL embedded statements. Host variables are a key of communication between the Oracle and C program. These variables are declared similarly as we make the declaration in the C program, and it can be referenced by both our program and Oracle.

The host variables can be placed where the SQL expressions are used, and these variables are declared between the BEGIN DECLARE SECTION and END DECLARE SECTION. When we write the SQL statements, then the host variables are prefixed with a ‘:’ colon.

The following is the list of the C data types that are supported by Oracle:

•Char

•char[n]

•int

•short

•long

•float

•double

•VARCHAR[n]

14.What is the role of Transaction in Pro*C?

Oracle Pro*C also follows the concept of the transaction as defined by the SQL standard. A transaction is a series of statements that Oracle uses to either make all the changes permanent or undo all the changes done since the transaction began. We use two statements, i.e., EXEC SQL COMMIT and EXEC SQL ROLLBACK. The EXEC SQL COMMIT statement is used to make all the changes permanent since the transaction began. The EXEC SQL ROLLBACK is used to undo all the changes since the transaction began. If we start the next transaction without writing the statement EXEC SQL COMMIT, then all the changes made during this transaction will be discarded.

15.What is Error Handling?

C programming provides the in-built error handling mechanism which we use in our source program. Error handling is a mechanism that provides the status of our source program. We need some mechanism that handles the error, so Pro*C contains the two error handling concepts which are given below:

•SQLCA (SQL Communication Area)

•Whenever statement

16.What is meant by SQLCA?

SQLCA (SQL Communication Area) is a data structure or an area used by our program to check for errors. This data structure contains some predefined variables used by Oracle. These variables contain the status information of the program, which is passed at runtime.

The structure of sqlca is given below:

struct sqlca {  

char sqlcaid[8];  

long sqlabc;  

long sqlcode;  

struct {  

unsigned short sqlerrml;  

char sqlerrmc[70];  

} sqlerrm;  

char sqlerrp[8];  

long sqlerrd[6];  

char sqlwarn[8];  

char sqlext[8];  

};  

17.What is Pointers?

A pointer variable can also be used as a host variable in SQL statements. Let’s understand through a simple example.

int *age;  

EXEC SQL SELECT age into :age from student; 

In the above code, we declare a pointer variable of integer type, i.e., *age. After declaration, we are executing a SELECT statement in which we are retrieving the value of age from the student table, and then we are storing the value of age in a host variable, i.e., age. The result will be stored in the *age, not in age.

18.What are Said to be Structures?

C structures are also used in Pro*C. The member variables of the structure can be treated as the host variables in the host program. When we provide the name of the structure in the SQL statement, then each host variable must be prefixed with a: colon.

struct student  

{  

int student_id;  

char name[20];   

}s1;  

EXEC SQL INSERT INTO stud(student id, name) values(:s1);  

In the above code, we have created a structure named as a student, which contains two variables, i.e., student_id and name. After creating structure, we declare the variable, i.e., s1 of type student. Then, we insert the value of these two variables in a database by using the insert command.

19.Explain about Dynamic vs Static SQL statements

Mainly, static SQL statements are used for fixed applications, but sometimes it is required for a program to create the SQL statements dynamically. To create the dynamic SQL statement, first, we need to store the SQL statement in a string variable. After storing the statement, we use the PREPARE statement to convert the character string into a SQL statement. Finally, we execute the statement by using the EXECUTE statement. Let’s understand this scenario through an example.

1.char *s = “INSERT INTO student VALUES(12, ‘Peter’, 3)”;  

2.EXEC SQL PREPARE q FROM :s;  

3.EXEC SQL EXECUTE q;  

20.What are the Components of SQLCA?

The following are the components of SQLCA:

•sqlcaid: It is an array of char characters which is initialized to “SQLCA”, and used to determine the SQL Communication area.

•sqlcabc: It is declared as an integer type to hold the length of the SQLCA structure in bytes.

•sqlcode: It is declared as an integer type that stores the status code of the most recently executed SQL statement. The status determines the outcome of the SQL statement, and the outcome can come in the following ways:

•sqlerrm: It is defined as a structure inside the sqlca.

21.What is an Array?

Array is a collection of similar types of elements. It stores the elements in contiguous memory locations, Moreover arrays can be one dimensional 2-dimensional and multi-dimensional.

Syntax:- datatype variablename[size];

Example:- int a[10];

After having known the arrays and pointers basically now we are here to cut the cake Pointers and arrays.

22.Explain the difference between Pointers and Arrays?

•An array is a collection of elements of similar data type whereas the pointer is a variable that stores the address of another variable. 

•An array size decides the number of variables it can store whereas; a pointer variable can store the address of only one variable in it.

•Arrays can be initialized at the definition, while pointers cannot be initialized at the definition.

•Arrays are static in nature which means once the size of the array is declared, it cannot be resized according to users requirement. Whereas pointers are dynamic in nature, which means the memory allocated can be resized later at any point in time.

•Arrays are allocated at compile time while pointers are allocated at runtime.

23. What is the usage of the pointer in C?

•Accessing array elements: Pointers are used in traversing through an array of integers and strings. The string is an array of characters which is terminated by a null character ‘\0’.

•Dynamic memory allocation: Pointers are used in allocation and deallocation of memory during the execution of a program.

•Call by Reference: The pointers are used to pass a reference of a variable to another function.

•Data Structures like a tree, graph, linked list, etc.: The pointers are used to construct different data structures like tree, graph, linked list, etc.

24.What is meant by a dangling pointer in C?

A Pointer in C Programming is used to point the memory location of an existing variable. In case if that particular variable is deleted and the Pointer is still pointing to the same memory location, then that particular pointer variable is called a Dangling Pointer Variable.

•If a pointer is pointing to any memory location, but meanwhile another pointer deletes the memory occupied by the first pointer while the first pointer still points to that memory location, the first pointer will be known as a dangling pointer. This problem is known as a dangling pointer problem.

•The dangling pointer arises when an object is deleted without modifying the value of the pointer. The pointer points to the deallocated memory.

25. What is pointer to pointer in C?

In case of a pointer to pointer concept, one pointer refers to the address of another pointer. The pointer to pointer is a chain of pointers. Generally, the pointer contains the address of a variable. The pointer to pointer contains the address of a first pointer.

26. Which variable can be used to access Union data members if the Union variable is declared as a pointer variable?

Arrow Operator( -> ) can be used to access the data members of a Union if the Union Variable is declared as a pointer variable.

27. How do you access the values within an array?

Arrays contain a number of elements, depending on the size you gave it during variable declaration. Each element is assigned a number from 0 to number of elements-1. To assign or retrieve the value of a particular element, refer to the element number. For example: if you have a declaration that says “int scores[5];”, then you have 5 accessible elements, namely: scores[0], scores[1], scores[2], scores[3] and scores[4].

28. What is the advantage of an array over individual variables?

When storing multiple related data, it is a good idea to use arrays. This is because arrays are named using only 1 word followed by an element number. For example: to store the 10 test results of 1 student, one can use 10 different variable names (grade1, grade2, grade3… grade10). With arrays, only 1 name is used, the rest are accessible through the index name (grade[0], grade[1], grade[2]… grade[9]).

29. Describe how arrays can be passed to a user-defined function?

One thing to note is that you cannot pass the entire array to a function. Instead, you pass to it a pointer that will point to the array first element in memory. To do this, you indicate the name of the array without the brackets.

30. What are valid operations on pointers?

•Assignment of pointers to the same type of pointers.

•Adding or subtracting a pointer and an integer.

•subtracting or comparing two-pointers.

•4-incrementing or decrementing the pointers pointing to the elements of an array. When a pointer to an integer is incremented by one, the address is incremented by two. It is done automatically by the compiler.

•Assigning the value 0 to the pointer variable and comparing 0 with the pointer. The pointer having address 0 points to nowhere at all.

GoLogica Technologies Private Limited. All rights reserved 2024.