Discussion
Can you combine the following two statements into one?
char *p;
p = (char*) malloc(100);
Answer: C
Correct answer: char *p = (char*)malloc(100);
A declaration may carry an initialiser, so the declaration and the assignment combine directly: char *p = (char*)malloc(100);.
The other forms misplace the asterisks. (char)malloc(100) casts the returned pointer to a single character, and the last option is not valid syntax at all. It is worth adding that in C the cast is unnecessary - void * converts to any object pointer type implicitly, and omitting the cast can expose a missing stdlib.h that the cast would hide.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development