Copa Final Exam Paper
Copa Final Exam Paper
Copa Final Exam Paper
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 XOR – ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with it.
0101
0110
------
XOR 0011
------
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];
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
Array Structure
i. Data Collection
Array elements are referred by subscript. Structure elements are referred by its unique name.
Array elements are accessed by it's Stucture elements are accessed by its object as '.'
position or subscript. operator.
v. Syntax
struct struct_name
{
structure element 1;
structure element 2;
<data_type> array_name[size]; ----------
----------
structure element n;
}struct_var_nm;
vi. Example
struct item_mst
{
int rno[5]; 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:
<data-type> <array_name> [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:
<data-type> <array_nm> [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.'
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
#include<stdio.h>
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);
}
7
7
007
5.10
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<iostream>
1.#include<conio>
2.int main()
3.{
4.int arr[10];
5.int i,j,sum=0,flag;
7.for(i=0;i<10;i++)
9.for(i=0;i<10;i++)
10.{
12.for(j=i+1;j<10;j++)
14.flag=1;
16.sum=sum+arr[i];
17.}
20.}
Initializing Variables
Before a variable can be used it must be given an initial value. This is called initializing the
variable. If we try to use a variable without first giving it a value:
int numberOfDays;
//try and add 10 to the value of numberOfDays
numberOfDays = numberOfDays + 10;
the compiler will throw an error:
variable numberOfDays might not have been initialized
To initialize a variable we use an assignment statement. An assignment statement follows the
same pattern as an equation in mathematics (e.g., 2 + 2 = 4). There is a left side of the
equation, a right side and an equals sign (i.e., "=") in the middle. To give a variable a value, the
left side is the name of the variable and the right side is the value:
int numberOfDays;
numberOfDays = 7;
In the above example, numberOfDays has been declared with a data type of int and has been
giving an initial value of 7. We can now add ten to the value of numberOfDays because it has
been initialized:
int numberOfDays;
numberOfDays = 7;
numberOfDays = numberOfDays + 10;
System.out.println(numberOfDays);
Typically, the initializing of a variable is done at the same time as its declaration:
//declare the variable and give it a value all in one statement
int numberOfDays = 7;
Que 13 Explain Global and local varible..Write “C” Program to explain global and local
varible.
Que 14 write a program in “C” to declare the structure employee having member
varible emp-id , name and phone no . Accept to data for 5 employees and display it.
1. #include
2. using namespace std;
3. struct persontag {
4. char name[ 20 ];
5. int age;
6. float salary;
7. }employee;
8. main( ){
9. cout << " ENTER EMPLOYEE NAME: ";
10. cin >> employee.name;
11. cout << " ENTER EMPLOYEE AGE: ";
12. cin >> employee.age;
13. cout << " ENTER EMPLOYEE SALARY:";
14. cin >> employee.salary;
15. cout << " NAME IS " << employee.name s<< endl;
16. cout << "AGE IS " << employee.age << endl;
17. cout << " SALARY IS " << employee.salary << endl;
18. return 0;
19. }//MAIN
Que 15 write a “C” Program to display menu. Addition, Subtraction , multiplication,
Division and Execute it using switch case (Accept two nos. From User)
{
//input declarations as doubles for total and counter
double total = 0, counter =0;
//input declarations sign and Q as character
char sign, Q = 0;
//input declaration value as double
double value;
//A do..while will loop forever (or until we hit the break statement)
do
{
//The current value is 0.
cout << "Result :"<<" "<< total << '\n';
//While the operation is not equal to 'Q', the program will run.
while (sign != 'Q');
return 0;
}
Incrementing a Pointer
We prefer using a pointer in our program instead of an array because the variable
pointer can be incremented, unlike the array name which cannot be incremented
because it is a constant pointer. The following program increments the variable
pointer to access each succeeding element of the array:
#include <stdio.h>
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr;
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr;
Output
Enter String
WELCOME
Length=7
Program to copy one string into another string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
clrscr ();
puts(“Enter String”);
gets(s1);
strcpy(s2, s1);
printf (“S1=%s\n”, s1);
printf (“S2=%s\n”, s2);
getch ();
}
Output
Enter String
Hello
S1=Hello
S2=Hello
Program to concate two strings.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[40],s2[20];
clrscr ();
puts(“Enter String1”);
gets(s1);
puts(“Enter String2”);
gets(s2);
strcat(s1, s2);
printf (“S1=%s\n”, s1);
getch ();
}
Output
Enter String1
Hello
Enter String2
Welcome
S1=HelloWelcome
Program to compare two strings.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
int ans;
clrscr ();
puts(“Enter String1”);
gets(s1);
puts(“Enter String2”);
gets(s2);
ans=strcmp(s1, s2);
if (ans == 0)
printf (“String are equal);
else
printf("String are Not equal");
getch ();
}
Output
Enter String1
MAX
Enter String2
MIN
String are not equal
Program to reverse given string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20];
clrscr ();
puts(“Enter String”);
gets(s1);
printf (“Original String is %s\n”, s1);
strrev(s1);
printf (“Reverse is %s\n”, s1);
getch ();
}
Output
Enter String
NODE
Original String Is NODE
Reverse is EDON
Program to find one string into another string.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
clrscr ();
puts(“Enter Original String”);
gets(s1);
puts(“Enter Search String”);
gets(s2);
if ( strstr(s1, s2)==NULL)
printf (“String Not Found");
else
printf (“String Found”);
getch ();
}
Output
Enter Original String
Hello How Are U
Enter Search String
How
String Found