The Department of Computer Science & Engineering
|
|
STUART C. SHAPIRO: CSE
305
|
6.3.1.4 Real floating and integer
...
[#1] When a finite value of real floating type is converted to integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
[ISO C Standard JTC1/SC22/WG14 N843]
Manual are written for programmers. They should specify all the operations, but some specifications may be implementation-dependent.
A in
the below C program?
#include <stdio.h>
void sub()
{
int x = 2;
printf("In sub, x = %d\n", x);
}
int main()
{
int x = 1;
printf("In main, x = %d\n", x);
A: sub();
printf("In main, x = %d\n", x);
return 0;
}
x given the value 1 in
the above C program?
void insert(int x, int a[], int open, int max) {
int i;
for (i = open; i < max; i++) {
if (x <= a[i+1]) {
a[i] = x;
return;
}
else {
a[i] = a[i+1];
}
}
a[max] = x;
}
void isort(int a[], int max) {
int i;
if (max >= 1) {
for (i = max-1; i >= 0; i--) {
insert(a[i], a, i, max);
}
}
}
(defun isort (list)
(if (or (endp list)
(endp (rest list)))
list
(insert (first list) (isort (rest list)))))
(defun insert (x list)
(cond ((endp list)
(list x))
((<= x (first list))
(cons x list))
(t (insert (first list)
(insert x (rest list))))))
isort([], []). isort([X], [X]). isort([First | Rest], Sorted) :- isort(Rest, Srest), insert(First, Srest, Sorted). insert(X, [], [X]). insert(X, [Y | Z], [X, Y | Z]) :- X =< Y. insert(X, [Y | Z], Result) :- insert(X, Z, Inter), insert(Y, Inter, Result).
This course will not be structured by these categories, but by PL components that all, or most, PLs have.