Commit 7817b51f authored by Alan Marchiori's avatar Alan Marchiori
Browse files

add lec3

parent 3ba4c7d9
#include <stdio.h>
int main(int argc, char* argv[]) {
float pi = 3.1415926;
char *pf = (char*) &pi;
int i;
printf("pi= %f\n\n", pi);
for (i=0; i<4; i++) {
printf("pf[%d]= %02x\n", i, 0xff & pf[i]);
}
}
#include <stdio.h>
int main(int argc, char* argv[]) {
float pi = 3.1415926;
char *pf = (char*) &pi;
int i;
printf("pi= %f\n\n", pi);
for (i=0; i<4; i++) {
printf("pf[%d]= %02hhx\n", i, pf[i]);
}
}
#include <stdio.h>
#include <stdlib.h>
int main(void){
struct employee_node{
char name[10];
int id;
float wage;
struct employee_node *next;
};
struct employee_node *first;
first = malloc(struct employee_node);
}
#include <stdio.h>
int main(void){
int i;
float x;
char text[80];
scanf("%d", &i);
scanf("%f", &x);
scanf("%s", text);
printf(" i= %d\n", i);
printf(" x= %f\n", x);
printf(" text= %s\n", text);
}
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i;
char p[] = "This is a test.";
for (i=0; i<strlen(p); i++) {
printf("%c", p[i]);
}
printf("\n\n");
printf("string starting at p= %s\n", p);
printf("content of p= %p\n\n", p);
char *s = p;
printf("string starting at s= %s\n", s);
printf("length= %d\n", (int) strlen(s));
printf("s[5]= %c\n", s[5]);
printf("*(s+6)= %c\n\n", *(s+6));
}
#include <stdio.h>
#include <stdlib.h>
int main(void){
struct employee_node{
char name[10];
int id;
float wage;
struct employee_node *next;
};
struct employee_node *first;
printf ("allocating %lu Bytes\n", sizeof(*first));
first = malloc(sizeof(*first));
printf ("memory is at %p\n", first);
}
#include <stdio.h>
#include <stdlib.h>
int main(void){
struct employee_node{
char name[10];
int id;
float wage;
struct employee_node *next;
};
struct employee_node *first;
printf ("allocating %lu Bytes\n", sizeof(first));
first = malloc(sizeof(first));
printf ("memory is at %p\n", first);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
{
int i = 999;
int j = 666;
printf("i= %d, j= %d\n", i, j);
{
int i = 123;
int j = i*i;
printf("i= %d, j= %d\n", i, j);
}
printf("i= %d, j= %d\n", i, j);
}
}
#include <stdio.h>
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
int main(int argc, char* argv[]) {
printf("%d, %c, %f, %lf\n", i, c, x, y);
printf("i@%p\n", &i);
}
#include <stdio.h>
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
int main(int argc, char* argv[]) {
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
printf("%d, %c, %f, %lf\n", i, c, x, y);
printf("i@%p\n", &i);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
int i = 7;
float x = 2.71828;
double y = 3.1415926;
char c = 'w';
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
#include <stdio.h>
int main(int argc, char* argv[]) {
static int i = 7;
float x = 2.71828;
static double y = 3.1415926;
char c = 'w';
printf("%d, %c, %f, %lf\n", i, c, x, y);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment