Microtechcomputers.weebly.com



SAMARTH ITI , Belhe

COPA Final Exam Paper with Expert Answer

Que 1 State and explain any four bitwise operators in c Programming.

C language supports the following bitwise operators.

| – Bitwise OR

& – Bitwise AND

~ – One’s complement

^ – Bitwise XOR

> – right shift

Bitwise OR – |

Bitwise OR operator | takes 2 bit patterns, and perform OR operations on each pair of corresponding bits. The following example will explain it.

1010

1100

--------

OR 1110

--------

Bitwise AND – &

Bitwise AND operator &, takes 2 bit patterns, and perform AND operations with it.

1010

1100

-------

AND 1000

-------

One’s Complement operator – ~

One’s complement operator (Bitwise NOT) is used to convert each “1-bit to 0-bit” and “0-bit to 1-bit”, in the given binary pattern. It is a unary operator i.e. it takes only one operand.

1001

NOT

-------

0110

-------

Bitwise XOR – ^

Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with it.

0101

0110

------

XOR 0011

------

Left shift Operator – >1;

Let’s take the binary representation of 8 assuming int is 1 byte for simplicity.

Position 7 6 5 4 3 2 1 0

Bits 0 0 0 0 1 0 0 0

Que 2 Explain Condition Operator With Syntax and Example

A traditional if-else construct in C,Java and JavaScript is written:

if (a > b) {

result = x;

} else {

result = y;

}

This can be rewritten as the following statement:

result = a > b ? x : y;

A GNU extension to C allows omitting the second operand, and using implicitly the first operand as the second also:

a = x ? : y;

The expression is equivalent to

a = x ? x : y;

except that if x is an expression, it is evaluated only once. The difference is significant if evaluating the expression has side effects.

C# and Perl provide similar functionality with their null coalescing operator.

a = x ?? y;

(Unlike the above usage of "x ?: y", ?? will only test if x is non-null, as opposed to non-false.)

Que 3 Explain Pointer variable . What are the advantage of using pointers?

Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data type likechar, int, float, double or user defined data type like function, pointer etc. or derived data type like array, structure, union,enum.

Examples:

int *ptr;

int (*ptr)();

int (*ptr)[2];

In c programming every variable keeps two type of value.

1. Contain of variable or value of variable.

2. Address of variable where it has stored in the memory.

(1) Meaning of following simple pointer declaration and definition:

int a=5;

int * ptr;

ptr=&a;

The basic advantages of using pointer are that, 

• It allows the use of dynamic memory allocation. 

• A pointer is a variable containing the address of a different variable of a type. 

• The concept of pointer is often scared because this is a technical programming very powerful for defining dynamic structures that is to say that advances over time.

Que 4 What do you mean by operators Precedence & Accociativity ? Explain With Example .

This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.

|Operator |Description |Associativity |

|( ) |Parentheses (function call) (see Note 1) |left-to-right |

|[ ] |Brackets (array subscript) | |

|. |Member selection via object name | |

|-> |Member selection via pointer | |

|++ -- |Postfix increment/decrement (see Note 2) | |

|++ -- |Prefix increment/decrement |right-to-left |

|+ - |Unary plus/minus | |

|! ~ |Logical negation/bitwise complement | |

|(type) |Cast (convert value to temporary value of type) | |

|* |Dereference | |

|& |Address (of operand) | |

|sizeof |Determine size in bytes on this implementation | |

|*  /  % |Multiplication/division/modulus |left-to-right |

|+  - |Addition/subtraction |left-to-right |

| |Bitwise shift left, Bitwise shift right |left-to-right |

|= |Relational greater than/greater than or equal to | |

|==  != |Relational is equal to/is not equal to |left-to-right |

|& |Bitwise AND |left-to-right |

|^ |Bitwise exclusive OR |left-to-right |

|| |Bitwise inclusive OR |left-to-right |

|&& |Logical AND |left-to-right |

|| | |Logical OR |left-to-right |

|? : |Ternary conditional |right-to-left |

|= |Assignment |right-to-left |

|+=  -= |Addition/subtraction assignment | |

|*=  /= |Multiplication/division assignment | |

|%=  &= |Modulus/bitwise AND assignment | |

|^=  |= |Bitwise exclusive/inclusive OR assignment | |

|= |Bitwise shift left/right assignment | |

|, |Comma (separate expressions) |left-to-right |

Que5 How Does a Structure diffrent from a Arrey ?

|Array |Structure |

|i. Data Collection |

|Array is a collection of homogeneous data. |Stucture is a collection of heterogeneous data. |

|ii. Element Reference |

|Array elements are referred by subscript. |Structure elements are referred by its unique name. |

|iii. Access Method |

|Array elements are accessed by it's position or subscript. |Stucture elements are accessed by its object as '.' operator. |

|iv. Data type |

|Array is a derived data type. |Structure is user defined data type. |

|v. Syntax |

| array_name[size]; |struct struct_name |

| |{ |

| |structure element 1; |

| |structure element 2; |

| |---------- |

| |---------- |

| |structure element n; |

| |}struct_var_nm; |

|vi. Example |

| int rno[5]; |struct item_mst |

| |{ |

| |int rno; |

| |char nm[50]; |

| |}it; |

Ques 6 Expalin Array . How Will You Declare one Dimensional and two dimensional arrey ?

Array :

Array is a collection of homogenous data stored under unique name. The values in an array is called as 'elements of an array.' These elements are accessed by numbers called as 'subscripts or index numbers.' Arrays may be of any variable type.

Array is also called as 'subscripted variable.'

Types of an Array :

1. One / Single Dimensional Array

2. Two Dimensional Array

Single / One Dimensional Array :

The array which is used to represent and store data in a linear form is called as 'single or one dimensional array.'

Syntax:

[size];

Example:

int a[3] = {2, 3, 5};

char ch[20] = "TechnoExam" ;

float stax[3] = {5003.23, 1940.32, 123.20} ;

Total Size (in Bytes):

total size = length of array * size of data type

In above example, a is an array of type integer which has storage size of 3 elements. The total size would be 3 * 2 = 6 bytes.

Two Dimensional Array :

The array which is used to represent and store data in a tabular form is called as 'two dimensional array.' Such type of array specially used to represent data in a matrix form.

The following syntax is used to represent two dimensional array.

Syntax:

[row_subscript][column-subscript];

Example:

int a[3][3];

In above example, a is an array of type integer which has storage size of 3 * 3 matrix. The total size would be 3 * 3 * 2 = 18 bytes.

It is also called as 'multidimensional array.'

Que7 What is the purpose of continue statement ?

The Continue Statement skips the current iteration of a for, while, or do-while loop. 

Unlabeled : The Unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. 

Example

class ContinueDemo {

public static void main(String[] args) {

String searchMe = "peter piper picked a peck of pickled peppers";

int max = searchMe.length();

int numPs = 0;

for (int i = 0; i < max; i++) {

//interested only in p's

if (searchMe.charAt(i) != 'p')

continue;

//process p's

numPs++;

}

System.out.println("Found " + numPs + " p's in the string.");

}

}

Here is the output of this program:

Found 9 p's in the string.

- The above program, ContinueDemo , steps through a String, counting the occurences of the letter "p". If the current character is not a p, the Continue Statement skips the rest of the loop and proceeds to the next character. If it is a "p", the program increments the letter counts.

To see this effect more clearly, try removing the Continue Statement and recompiling. When you run the program again, the count will be wrong, saying that it found 35 p's instead of 9.

Que 8 State the use of % C and % S in 'C' Program. Write Print Statement in 'C' Using Above Symbol.

printf Background

The printf function is not part of the C language, because there is no input or output defined in C language itself. The printf function is just a useful function from the standard library of functions that are accessible by C programs. The behavior of printf is defined in the ANSI standard. If the compiler that you’re using conforms to this standard then all the features and properties should be available to you.

Format Specifiers

There are many format specifiers defined in C. Take a look at the following list:

|%i or %d |int |

|%c |char |

|%f |float |

|%lf |double |

|%s |string |

Note: %lf stands for long float.

Let’s take a look at an example of printf formatted output:

#include

main()

{

int a,b;

float c,d;

a = 15;

b = a / 2;

printf("%d\n",b);

printf("%3d\n",b);

printf("%03d\n",b);

c = 15.3;

d = c / 3;

printf("%3.2f\n",d);

}

Output of the source above:

7

7

007

5.10

Ques 9 Explain “Call-By-Value” and “Call-By-Reference” in C Programming.

1) Call by Value:-when we call a Function and if a function can accept the Arguments from the Called Function, Then we must have to Supply some Arguments to the Function. So that the Arguments those are passed to that function just contains the values from the variables but not an Actual Address of the variable.

 

So that generally when we call a Function then we will just pass the variables or the Arguments and we doesn’t Pass the Address of Variables , So that the function will never effects on the Values or on the variables. So Call by value is just the Concept in which you must have to Remember that the values those are Passed to the Functions will never effect the Actual Values those are Stored into the variables.

 

2) Call By Reference :-When a function is called by the reference then the values those are passed in the calling functions are affected when they are passed by Reference Means they change their value when they passed by the References. In the Call by Reference we pass the Address of the variables whose Arguments are also Send. So that when we use the Reference then, we pass the Address the Variables.

 

When we pass the Address of variables to the Arguments then a Function may effect on the Variables. Means When a Function will Change the Values then the values of Variables gets Automatically Changed. And When a Function performs Some Operation on the Passed values, then this will also effect on the Actual Values.

Que 10 Write a “C” Program to Accept 10 integer numbers and Display them using Arrey.

#include

1. #include

2. int main()

3. {

4. int arr[10];

5. int i,j,sum=0,flag;

6. cout ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download