Docsity

c++ pointers and functions, Quizzes of Programming Languages

Toggle sidebar
bg1
Date: 01/12/2022
Student Name:……………….. Student ID:…………………..
Quiz I
I. What is the output of the following code? (5 Points)
1- #include <iostream>
using namespace std;
main(){
int a[] = {7, 8, 9, 10};
int *p = (a + 1);
cout<< *p<<endl; // (1) (1):…………8………. (2):………12………
cout<< *(p+1) + 3; //(2)
return 0;}
2- int a, b;
void modify()
{
a=40;
b=50;
}
main(){
int x,y;
x=30;
y=40;
b=100; (1):……300-50….. (2):……30-40……………
modify();
a=300;
cout<<"a="<<a<<" "<<"b= "<<b<<endl;//(1)
cout<<"x= "<<x<<" "<<"y= "<<y<<endl;//(2)
}
3- int main(){
int a = 50,b=100;
int &n=a;
n=a++; (1):……100-100…..
n = b;
cout<<a <<","<<n<<endl; //(1)
return 0;}
pf3

Partial preview of the text

Download c++ pointers and functions and more Quizzes Programming Languages in PDF only on Docsity!

Date: 01/12/ Student Name:……………….. Student ID:…………………..

Quiz I

I. What is the output of the following code? ( 5 Points )

1- #include using namespace std; main(){ int a[] = {7, 8, 9, 10}; int *p = (a + 1); cout<< *p<<endl; // (1) (1):………… 8 ………. (2):……… 12 ……… cout<< *(p+1) + 3; //(2) return 0;} 2- int a, b; void modify() { a=40; b=50; } main(){ int x,y; x=30; y=40; b=100; (1):……300-50….. (2):……30-40…………… modify(); a=300; cout<<"a="<<a<<" "<<"b= "<<b<<endl;//(1) cout<<"x= "<<x<<" "<<"y= "<<y<<endl;//(2) } 3- int main(){ int a = 50,b=100; int &n=a; n=a++; (1):……100-100….. n = b; cout<<a <<","<<n<<endl; //(1) return 0;}

4- int main(){ int v1=2, v2= -1, p1, p2,p3; p1 = & v1; p2= & v2; p2=p1; (1):……… 2 ………….. (2):……… 2 ………….. cout << p2 << endl;//(1) p3=p2; cout<<p3<< endl;//(2) } 5- What should be output of below program if user enter a = 5? int main() { int a; cin>>a; // user can enter any value if (++a5 < = 25) { cout<<"Hello"; ………………………Bye……………………………. } else { cout<<"Bye"; } } II. Write an application with a main method in which you: a) Create a function that read 4 salaries with data fields’ values given by the user. (1Points) Void ReadSalaries (int salary[],int size){ int i; for(i=0;i<size;i++) { cout<<"salary["<<i<<"]="; cin>>salary[i]; } b) Display the salary of every person. (1 Points) Void DisplaySalaries (int salary[],int size){ int i; for(i=0;i<size;i++) {cout<<salary[i]<<" "; }}