Lab Work 5. 25.07.2016
Chapter 6-7.
Goal: Data Types, Expression, Assignment.
- C functions return single value. Write a function that will return two values. Use a structure to do this. That is, you will be returning a structure.
- Access the elements of a structure in C/C++ without using the .or -> operator.
- Examine the following program and write down what gets printed and why. Copy the each statement given bellow and paste to the “statement goes here”. Then run the program and compare your answer.
#include “stdio.h”
int fun2();
int a = 5;
int fun1() {
a = 17;
return 3;
}
void main() {
/* put statements here*/
printf(“%d“,a);
}
int fun2() {
return a;
}
Statements :
a)a = fun1()+fun2();
b)a = fun2()+fun1();
c)a = fun1()+a;
d) a = a+fun1();
e) a = a+fun1()+a++;
f) a = a+++fun1();
g) a = ++a+fun1();
h) ++a+fun1();
i) a = a+++++a; // fix the lvalue error
- Examine the following program and write down what gets printed and why.Then run the program and compare your answer.
#include “stdio.h”
voidmain() {
int k = 1;
int i = 0;
printf(“%d “, (i & k++)?i:k);
}
- Examine the following program and determine which statements are returning true and false.Then run the program and compare your answer.
#include “stdio.h”
void main() {
int i=5, j=7, k=2; float f=11.75; char c =’K’;
printf(“%d”, /* put statements here*/);
}
Statements :
a) (i >= 5 || j + 3 == k)d)( j + 3 == k * 4 || c >= ‘Z’)
b) (‘A’ <= c & f + 7.2 != 2.5) e)( i < 3 & j > k)
c) ( !(3 * i + 4 < k * 2))f)( i + 4 > k || f > i + 20 & k < 5)