Question

Problem - 1: For the following declarations below, indicate which of the following statements are valid or not 5 Points int A

0 0
Add a comment Improve this question Transcribed image text
Answer #1
include <iostream>
using namespace std ;
int main() {

    //problem 1 part 1

    int *yAddist;// declaring pointer to an int

    int a ;
    //&a means address of  variable a
    //variable yAddist is declared  to hold address of an int

    yAddist = &a ;  //assigning address of an int to an int pointer
                    // which is a valid assignment



return 0 ;

}

Process finished with exit code θ


#include <iostream>
using namespace std ;
int main() {

    //problem 1  part 3

    int *yAddist , *At1 ;//  declaring 2 pointers  to an int

   // now At1 and yAddist can store address of an int
    // currently At1 is not initialized and contain the garbage value
    //which will be assignes to yAddist
    // since type missmatch is  not occuring so compiler will give no error


yAddist = At1;
    cout<< " valid statement"<< endl;
return 0 ;

}

valid statement Process finished with exit code θ

#include <iostream>
using namespace std ;
int main() {

    //problem 1  part 5



    long *ptAddst;
    //so ptAddst can store address of any variable with type long
    // b is a variable whose type is long
    long  b ;
    //&b means address of variable b
    // so address of b is assignes to a variable which can store address of any
    // double variable
    // so the assignment is valid ;

    ptAddst = &b;

cout<< " valid assignment "<< endl;

return 0 ;

}

valid assignment | ↓ | as Process finished with exit code θ


#include <iostream>
using namespace std ;
int main() {

    //problem 1  part 2
double  c ;// c is a variable of type double
    int *yAddst;
    //since yAddst is a pointer to an int
    //so variable yAddst can store address of any variable with type int


    // we cannot assign address of a double to a pointer of type int
    //type miss match happend
    //so error

    yAddst = &c ;



cout<< "  invalid  assignment "<< endl;

return 0 ;

}

\Userslashok CLionProjectsluntitled15 main.cpp:18:12: error: cannot convert double* to int* in assignment

#include <iostream>
using namespace std ;
int main() {

    //problem 1  part 4


    double *ptZ ;// ptZ can point to any variable of type double
    int a ;// variable a  is of type int 

    // here we are trying to assign address of a variable of type int to a variable
    //which can store address of double
    //so type miss match happend  , compiler will give error
    ptZ = &a ;

    

return 0 ;

}

C:\Users ashok\CLionProjectsluntitled151main.cpp:16:9: error: cannot convert int* to double* in assignment

Add a comment
Know the answer?
Add Answer to:
Problem - 1: For the following declarations below, indicate which of the following statements are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first numbe...

    Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first number in the file will be an integer, and will indicate the amount of decimal numbers to follow. Once you have the read the numbers from the file into an array then compute the following properties on the set of numbers: the sum, the average (mean), the variance, the standard deviation, and the median. Don’t try to do the entire program...

  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • Submission Items: (1) A Word document in which you: a. Describe in brief the problem you...

    Submission Items: (1) A Word document in which you: a. Describe in brief the problem you are solving and the numerical method used. b. Snapshot of the output, when you run the program for the conditions mentioned in the questions. c. Discuss your results. (2) MATLAB code (m) file() Question 1: [10 points) Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation: arctan(x) = x- + +... The function should accept 3 parameters:...

  • 1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi...

    1 of 1 15 points) Palindrome Detector. A palindrome is a phrase that reads the Pi same ronwards as it does backwards. For example, "a man, a plan, a canal, Panama is a palindrome. Write a program that uses a stack to check for palindromes in each line of a text file. Try your program on the example text file "palindromes txt".Your program should output the palindromes that it finds in the document. For example: FindPalindromes( palindromes.txt") will display "a...

  • Write a javascript program which implements the following two classical cryptosystem which we covered in class:...

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

  • i need the answer to be on a MatLab window 1. Consider the following equation, which...

    i need the answer to be on a MatLab window 1. Consider the following equation, which represents the concentration (c, in mg/ml) of a drug in the bloodstream over time (t, in seconds). Assume we are interested in a concentration of c2 mg/ml C3te-0.4t A. Estimate the times at which the concentration is 2 mg/ml using a graphical method Be sure to show your plot(s). Hint: There are 2 real solutions B. Use MATLAB to apply the secant method (e.g....

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts...

    Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts an annual summer meeting. Each state sends one official delegate to the section officers’ meeting at this summer session. The national organization reimburses the official state delegates according to the scale below. Write a Java program to calculate the reimbursement values, satisfying the specifications below. Details on array and method usage follow these specs. 1. The main method should declare all the variables at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT