A structure is a user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
--------------------------------------------------------------------------------------------------------
1.
What is the output?
#include
struct student
{
char *name;
};
struct student s;
struct student fun(void)
{
s.name = "newton";
printf("%s\n", s.name);
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s\n", m.name);
m.name = "turing";
printf("%s\n", s.name);
}
A. newton alan alan
B. alan newton alan
C. alan alan newton
D. Compile time error
Answer: A
------------------------------------------------------------------------------------------------
2.
The output of the code below is
#include
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
s.name = "turing";
printf("%s", m.name);
}
A. alan
B. Turing
C. Compile time error
D. Nothing
Answer: C
--------------------------------------------------------------------------------------------------
3.
Which of the following accesses a variable in structure b?
A. b->var;
B. b.var;
C. b-var;
D. b>var;
Answer: B
----------------------------------------------------------------------------------------------------
4.
Which of the following is a properly defined struct?
A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};
Answer: D
----------------------------------------------------------------------------------------------------
5.
Which properly declares a variable of struct foo?
A. struct foo;
B. struct foo var;
C. foo;
D. int foo;
Answer: B
----------------------------------------------------------------------------------------------------
6.
Which of the following return-type cannot be used for a function in C?
A. char *
B. struct
C. void
D. none of the mentioned
Answer: D
-----------------------------------------------------------------------------------------------------
7.
Find the output?
#include
struct temp
{
int a;
} s;
void func(struct temp)
{
s.a = 10;
printf("%d\t", s.a); s
}
main()
{
func(s);
printf("%d\t", s.a);
}
A. 10 (Garbage Value)
B. 0 10
C. 10 0
D. (Garbage Value) 10
Answer: C
----------------------------------------------------------------------------------------------
8.
Presence of code like “s.t.b = 10” indicate.
A. Syntax Error
B. structure
C. double data type
D. An ordinary variable name
Answer: B
----------------------------------------------------------------------------------------------
9.
Find the output?
#include
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
s.name = "turing";
printf("%s", m.name);
}
A. alan
B. Turing
C. Compile time error
D. Nothing
Answer: C
-----------------------------------------------------------------------------------------
More imp topics:
The output of the code below is
#include
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
s.name = "turing";
printf("%s", m.name);
}
A. alan
B. Turing
C. Compile time error
D. Nothing
Answer: C
--------------------------------------------------------------------------------------------------
3.
Which of the following accesses a variable in structure b?
A. b->var;
B. b.var;
C. b-var;
D. b>var;
Answer: B
----------------------------------------------------------------------------------------------------
4.
Which of the following is a properly defined struct?
A. struct {int a;}
B. struct a_struct {int a;}
C. struct a_struct int a;
D. struct a_struct {int a;};
Answer: D
----------------------------------------------------------------------------------------------------
5.
Which properly declares a variable of struct foo?
A. struct foo;
B. struct foo var;
C. foo;
D. int foo;
Answer: B
----------------------------------------------------------------------------------------------------
6.
Which of the following return-type cannot be used for a function in C?
A. char *
B. struct
C. void
D. none of the mentioned
Answer: D
-----------------------------------------------------------------------------------------------------
7.
Find the output?
#include
struct temp
{
int a;
} s;
void func(struct temp)
{
s.a = 10;
printf("%d\t", s.a); s
}
main()
{
func(s);
printf("%d\t", s.a);
}
A. 10 (Garbage Value)
B. 0 10
C. 10 0
D. (Garbage Value) 10
Answer: C
----------------------------------------------------------------------------------------------
8.
Presence of code like “s.t.b = 10” indicate.
A. Syntax Error
B. structure
C. double data type
D. An ordinary variable name
Answer: B
----------------------------------------------------------------------------------------------
9.
Find the output?
#include
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
s.name = "turing";
printf("%s", m.name);
}
A. alan
B. Turing
C. Compile time error
D. Nothing
Answer: C
-----------------------------------------------------------------------------------------
More imp topics: