Identify the incorrect syntax for a pointer to a structure:Assuming the structure: struct temp { int b; } *obj;
Question
Identify the incorrect syntax for a pointer to a structure:Assuming the structure: struct temp { int b; } *obj;
Solution
The syntax you provided for declaring a pointer to a structure is correct. Here is how it works:
-
struct tempis the declaration of the structure. This structure contains one member:int b. -
*objis the declaration of a pointer to a structure of typetemp. The asterisk (*) beforeobjindicates thatobjis a pointer.
So, struct temp { int b; } *obj; is a correct syntax for declaring a pointer to a structure in C/C++.
However, if you want to see an incorrect syntax, here are a few examples:
struct temp { int b } *obj;- This is incorrect because it lacks a semicolon (;) at the end of the structure declaration.struct temp { int b; } obj*;- This is incorrect because the asterisk (*) should be beforeobj, not after.struct temp { int b; } *;- This is incorrect because it lacks the name of the pointer (in this case,obj).
Similar Questions
Which of the following structure declaration will throw an error?Question 32Select one:struct temp{}s; main(){}struct temp{}; struct temp s; main(){}struct temp s; struct temp{}; main(){}None of the mentioned
How do you access a member of a structure using a structure pointer in C?*1 pointWith the dot operator (.)With the arrow operator (->)With the ampersand (&)With the asterisk (*
How do you declare a structure in C?struct { int a; float b; } myStruct;struct myStruct { int a, float b};struct myStruct { int a; float b; };struct myStruct int a; float b; myStruct;struct { int a; float b; };
If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
Multi Choice Type QuestionWhich of these is the correct way to declare a structure variable after defining a structure in C?Marks : 1Negative Marks : 0Answer herestruct point p1, p2;point struct p1, p2;struct point = {p1, p2};point p1, p2;
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.