using namespace std;
int main() {
int a[6]={2,1,3,15,20,50};
int i=++a[1];
int j=a[1]++;
int k=a[i++];
int l=a[--i]*i;
int m=a[++i]-1;
couti" "j" "k" "l" "m" ";
return 0;
}
int main() {
int a[6]={2,1,3,15,20,50};
int i=++a[1];
int j=a[1]++;
int k=a[i++];
int l=a[--i]*i;
int m=a[++i]-1;
couti" "j" "k" "l" "m" ";
return 0;
}
output
3 2 3 6 14
2. Bitwise operators to mention
& =bitwise AND operator
| =btwise OR operator
^ =bitwise Exclusive OR operator
~ =bitwise NOT operator
3.
int A[5] = {1 , 2, 3, 4};
int i;
for (i=0; i<5; i++)
{
A[i] = 2*A[i];
Cout<< A[i] " ";
}
output
2 4 6 8 118
4.
What will be the output of the following; (5 marks)
void main()
{
union Num
{
int ValueI;
float ValueF;
double ValueD;
char ValueC;
};
Num TestVal = {100};
cout"Integer =" TestVal.ValueIendl;
TestVal.ValueF = 2.123;
cout "Float=" TestVal.ValueFendl;
cout"Uninitialzed double =" TestVal.ValueD endl;
cout"Some rubbish???"endl;
TestVal.ValueC = 'U';
cout"character=" TestVal.ValueCendl;
}
output
Integer = 100
Float= 2.123
Uninitializad double 5.30754e-315
Some rubbish???
Character = U
5.
#include <iostream.h>
main ()
{
int y[10] = {10,20,30,40,50,60,70,80,90,100};
int *yptr, i;
yptr = y;
cout*(yptr+1*2)endl;
}
output
30
Q) what will be the Out put of
int x=10;
int y=30;
int *xptr;
xptr=&x;
cout "x = " *xptr+x ; (Out put signs are present but cant write here )
int x=10;
int y=30;
int *xptr;
xptr=&x;
cout "x = " *xptr+x ; (Out put signs are present but cant write here )
Answer: x=20
Q))When a pointer is incremented then how many bytes will it move to change its address? Ans:When a pointer is incremented, it actually jumps the number of memory addresses
Q))When a pointer is incremented then how many bytes will it move to change its address? Ans:When a pointer is incremented, it actually jumps the number of memory addresses
►According to data type (Pg 160)
“If an integer occupies four bytes in the memory, then the yptr++; will increment its value by four. when we increment the yptr, it
points to the next integer in the memory”
It depends on the data type of the size. *ptr++ this pointer will point to the next element in the array.
Q 3 : If ( char array [7], is a character array then write a char at fifth loction of this array.
Q 3 : If ( char array [7], is a character array then write a char at fifth loction of this array.
char[4]=’a’;
Q 4 : Which function is used in read & write while handling file.
ifstream inFile; // object for reading from a file
ofstream outFile; // object for writing to a file
1:intPtr is a constant pointer to integer 155
int *const intPtr= &x;
2:intPtr is a pointer to constant
const int *intPtr = &x;
q3: Char name []= " Hello World";
size of array name ?
ans :12 including space and NULL character
double atof (const char *nptr)
Answer: page 191
Converts the string nPtr to double.
char *strcpy (char *s1,const char *s2)
Answer: page 192
Copies string s2 into character array s1. The value of s1 is returned.
q5 tel the size of initialized array
int arr []={0,0,0,0}
ans: 4
--We are trying to open a txt file which does not exist with command (“myfile.txt”, ios::out); (2 marks)
Ofstream.out;
Out.open(“myfile.txt”, ios::out);
If(!out) { cout<<”not found”; exit(1);}
A new file will be created and now we have to add our data in this file.
---A two-dimensional array has 2 rows and 3 columns. Write down the syntax to initialize first element of all rows of two-dimensional array with value 3 (2 marks)
int num[2] [3] ;
num[0] [0] =3;
num[1] [0]=3 ;
num[2] [0]=3 ;
Q)) When a pointer is incremented,what happens in the following cases?page#172
a)single-dimensional array
b)two –dimensional array 3
a)single-dimensional array
b)two –dimensional array 3
Comments
Post a Comment
Please give us your feedback & help us to improve this site.