Professional Documents
Culture Documents
ASSIGNMENT No. 02
Submission Date
Due Date
*By signing above, you attest that you have contributed to this submission and
confirm that all work you have contributed to this submission is your own work. Any
suspicion of copying or plagiarism in this work will result in an investigation of
Academic Misconduct and may result in a “0” on the work, an “F” in the course, or
possibly more severe penalties.
Page 2 of 4
Lab Tasks
Task # 1
Program Statement:
Introduce int variables x and y and int* pointer variables p and q. Set x to 2, y to 8, p to the
address of x, and q to the address of y. Then print the following information
(1) The address of x and the value of x.
(2) The value of p and the value of *p.
(3) The address of y and the value of y.
(4) The value of q and the value of *q.
(5) The address of p (not its contents!).
(6) The address of q (not its contents!).
Program Code:
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
int x,y;
int *p,*q;
x=2;
y=8;
p=&x;
q=&y;
cout<<"The address of x is "<<&x<<" and the value of x is "<<x<<endl;
cout<<"The value of p is "<<p<<" and the value of *p is "<<*p<<endl;
cout<<"The address of y is "<<&y<<" and the value of y is "<<y<<endl;
cout<<"The value of q is "<<q<<" and the value of *q "<<*q<<endl;
cout<<"The address of p (not its contents!) is "<<&p<<endl;
cout<<"The address of q (not its contents!) is "<<&q<<endl;
System(“pause”);
}
Page 3 of 4
Program Output:
Task #2
Program Statement:
Write a program that inputs an array of 10 elements. The program then calls a function, sending
it the array as an input argument and the function then determines the count of even and prime
numbers in the array and display the result.
Program code:
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
int arr[10], i, p=0, c, prime=0;
for(i=0;i<10;i++)
{
cout<<"Enter an integer:";
cin>>arr[i];
}
Page 4 of 4
Program Output: