Languages [3i Infotech Placement]: Sample Questions 356 - 357 of 546
Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.
Question 356
Explanation
- Typedef is keyword used to assign alternative names to existing datatypes.
- Mostly used with user defined datatype, when names of the datatypes become slightly complicated to use in programs.
Syntax for using typedef:
Typedef < existing_name >< alias_name >
Application of typedef:
- Typedef can used to a name to user defined data type as well.
- For example structure:
typedef struct
{
type member1;
type member2;
type member3;
} type_name;
Question 357
Describe in Detail Essay▾
What is the output of the following program?
main ()
{
void swap ();
int x =10, y =8;
swap (&x, &y);
printf ( “x =%d y =%d”, x, y);
}
void swap ()
int ⚹a, int ⚹b
{
⚹a^=⚹b,⚹b^=⚹a,⚹a^=⚹b;
}
Explanation
In the program using ^ swaps two variables without using a temporary variable and that too in a single statement.
void swap () ; |
|
int x = 10, y = 8; |
|
swap (&x, &y) ; |
|
printf ( “x =% d y =% d” , x, y) ; |
|
Modern style of declaration: void swap (int ⚹ a, int ⚹ b) { ⚹ a ^ =⚹ b, ⚹ b ^ =⚹ a, ⚹ a ^ =⚹ b; } | void swap () int ⚹ a, int ⚹ b { ⚹ a ^ =⚹ b, ⚹ b ^ =⚹ a, ⚹ a ^ =⚹ b; }
|