The following code is not portable for a particular reason. What is that reason and what problem does it have? This code is in C.
char c = 148;
int i = 2000;
printf(“i divided by c is %d\n”, i / c);
Portability Of C program:
Firstly, C programs are meant to be portable as long as your desired target platform has a working C compiler available, you can move your C source code that target platform by recompiling it, without having to modify it.
Problem :
The above code is not portable because of few exceptions of char datatype whether signed or unsigned (the standards aren't specified, that is to make C code portable we cannot make assumptions on the size of any data type other than char).
It's mostly portable. It has standard libraries - but not all OSes support all features in the same way. You CAN write code that's specific to particular operating systems.
The output of the program:
i divided by c is -18
Reason: There is no specification of char datatype whether it is signed or unsigned because of this the code may not be portable,
Get Answers For Free
Most questions answered within 1 hours.