Question

Consider: typedef struct { int x; int y; } Point; Point p; Point* pp; Assign the...

Consider:

typedef struct { int x; int y; } Point; Point p; Point* pp; Assign the coordinates (10, 20) to point p.

choose the following Multiple choice question

1.) p[x] = 10; p[y] = 20;

2.) p->x = 10; p->y = 20;

3.) p(x) = 10; p(y) = 20;

4.) p.x = 10; p.y = 20;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer)4.) p.x = 10; p.y = 20;

p is pointer variable pointing to structure Point. x and y are variables in structure.p.x is used to access x variable in structure Point and p.y is used to access y variable in structure Point.

#include <stdio.h>
typedef struct { int x; int y; } Point;Point p;
int main()
{
p.x=10;
p.y=20;
printf("%d %d",p.x,p.y);

return 0;
}

10 20 ... Program finished with exit code 0 Press ENTER to exit console. I

Add a comment
Know the answer?
Add Answer to:
Consider: typedef struct { int x; int y; } Point; Point p; Point* pp; Assign the...
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
  • can someone explain what is going on inside the strcut? c++ struct Pos{ int x; int...

    can someone explain what is going on inside the strcut? c++ struct Pos{ int x; int y; // coordinates Pos(const Pos &p, int dx=0, int dy=0){ *this = p; x+=dx; y+=dy;}    Pos(int _x, int _y){ x=_x; y=_y; } //new location    bool operator<(const Pos & p) const { return (x < p.x) || (x==p.x && y < p.y); }       bool operator==(const Pos & p) const { return x==p.x && y==p.y; } Pos(){x=-1;y=-1;} };

  • Canvas → XC D Question 13 Given the code below: typedef struct p { char topic...

    Canvas → XC D Question 13 Given the code below: typedef struct p { char topic [20]; int nunWords; > page; typedef struct mag char name[20]; page pages [250); int numPages; } magazine; magazine m; How would you declare an array of 20 magazines? struct magazine[20] magazine[20] magazine myStack(20) None of the above struct m[191 Question 14 Given the code below: typedef struct char topic[20] Canvas & XC struct m[19] Question 14 Given the code below: typedef struct char topic[20];...

  • C programming language 4. (Memory allocation) Consider typedef struct char name [20]; int balance; int gain;...

    C programming language 4. (Memory allocation) Consider typedef struct char name [20]; int balance; int gain; ) Player; int ni Player pi scanf ("%d", &n); Complete the code above by allocating a memory for n players each of which of type Player and making p point to the start of that memory (or in other words, making p have the value of the starting address of that memory). [Recall the slides on dynamic memory allocation function malloc.]

  • In the following code, A and B are constants defined with #define: 1 typedef struct {...

    In the following code, A and B are constants defined with #define: 1 typedef struct { 2 int x[A][B]; /* Unknown constants A and B */ 3 long y; 4 } str1; 5 6 typedef struct { 7 char array[B]; 8 int t; 9 short s[A]; 10 long u; 11 } str2; 12 13 void setVal(str1 *p, str2 *q) { 14 long v1 = q-<t; 15 long v2 = q-<u; 16 p-<y = v1+v2; 17 } gcc generates the following...

  • Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the...

    Write a generic function int find_lower_bound(T seq[], int n, const T& value). The function returns the index of the largest element in the given sequence that is less than the given value. If multiple elements satisfy, return the one with smallest index. Return -1 if no such element exists. //main.cpp #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; #include "source.h" struct Point{    int x,y;    bool operator<(const Point& p) {        return (x<p.x || (x==p.x&&y<p.y));    } }; int...

  • In this exercise, you will make a struct that contains x and y coordinates: struct point...

    In this exercise, you will make a struct that contains x and y coordinates: struct point {int x; int y;}; The object of this exercise is to make a singly linked list of these point structures. Add one more member called "next" to your point struct. It is a pointer to the next member of the linked list. The next member of the last point struct should point to NULL, which indicates the end of the list. Your program will...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int heig...

    CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...

  • struct my_coord { int x; int y; double altitude; }; struct my_line { struct my_coord first;...

    struct my_coord { int x; int y; double altitude; }; struct my_line { struct my_coord first; struct my_coord second; char name[10]; }; struct my_coord var; struct my_coord array[3]; struct my_line one_line; struct my_line two_lines[2]; Draw the memory layout of the prior four variables; var, array, one_line, and two_lines on a line of boxes. Label the start of each variable and clearly show how many bytes each element within each structure variable consumes.

  • Consider a file of records of the following type: typedef struct { int id; // unique...

    Consider a file of records of the following type: typedef struct { int id; // unique identifier char desc[100]; // description of item float price; // wholesale price } Record; And the following variables: int fd; // file descriptor, open on file for read/write Record rec; // record which is set to appropriate values If the file is non-empty and fd is currently positioned at the end-of-file, which of the following pairs of statements will update the 11th record in...

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
ADVERTISEMENT