Sail E0 Webinar
Question


If int is 2 bytes wide.What will be the output of the program?


#include<stdio.h>
void fun(char**);
int main()
{
char *argv[] = {"ab", "cd", "ef", "gh"};
fun(argv);
return 0;
}
void fun(char **p)
{
char *t;
t = (p+= sizeof(int))[-1];
printf("%s\n", t);
}
Options:
A .  ab
B .  cd
C .  ef
D .  gh
Answer: Option B

Since C is a machine dependent language sizeof(int) may return different values.

The output for the above program will be cd in Window (Turbo C) and gh in Linux (GCC).

To understand it better, compile and execute the above program in Windows (with Turbo C 

compiler) and in Linux (GCC compiler).




Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers