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 temp
is the declaration of the structure. This structure contains one member:int b
. -
*obj
is the declaration of a pointer to a structure of typetemp
. The asterisk (*) beforeobj
indicates thatobj
is 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
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?
Which of the following cannot be a structure member?*1 pointA. FunctionB. ArrayC. StructureD. None of the above
Prior to using a pointer variable it should beQuestion 2Answera. Declaredb.None of thesec. Both declared and initalizedd. Initialized
Which of the following cannot be a structure member?Question 19Select one:Another structureFunctionArrayNone of the mentioned
Which keyword is used to declare an object of a class in C++?objectstructnewclass
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.