a = b * c == 2 a = b && a > z ? x = y : z a = s . f + x . y a = b >> 2 + 4 c = getchar() == EOF
int *p; p = NULL; if (*p == 13) printf(" got it!\n");Will the following fragment of code also produce a segmentation fault? Why or why not?
int *p; p = NULL; if (p != NULL && *p == 13) printf("got it!\n");
i = 2; switch(i){ case 1: printf("moo\n"); case 2: printf("baa\n"); case 3: printf("meep\n"); case 4: printf("sproing\n"); }
/* Count the number of a's */ /* in a line given as input */ #include <stdio.h> #include <ctype.h> void main(void) { int num_a = 0; int c; c = getchar(); while(1) { if (c == '\n') break; if (isdigit(c)) continue; if (c == 'a') goto add_num_a; get_next_char: c = getchar(); goto end_loop; add_num_a: num_a++; goto get_next_char; end_loop: ; } printf("%d\n", num_a); exit(0); }
char *c[] = { "ENTER", "NEW", "POINT", "FIRST" }; char **cp[] = { c+3, c+2, c+1, c }; char ***cpp = cp; main() { printf("%s", **++cpp ); printf("%s ", *--*++cpp+3 ); printf("%s", *cpp[-2]+3 ); printf("%s\n", cpp[-1][-1]+1 ); }Hint: Draw a picture of the arrays and the pointers.
#define min(a, b) ((a) > (b) ? (b) : (a))and here is a function:
int min(int a, int b) { return(a > b ? b : a); }In the following code fragment, give the values of a, b, c, d, and e at the end if min is the above macro, and then if min is a function call:
a = 2; b = 3; c = 4; d = min(++a, b); e = min(c++, b);
int testandinc(int x) { return(x++); } int p1testandinc(int *x) { return(*x++); } int p2testandinc(int *x) { return((*x)++); }Give the values of a, b, c, d, e, f, and the elements of the array at the end of this code fragment. (Remember that b and c are pointers, so express their values by using the variables they point to; for example, if b poointed to a, then write b's value as &a.)
int a = 2; int arr[3] = { 3, 4, 5 }; int *b = arr; int *c = &arr[1]; d = testandinc(a); e = p1testandinc(b); f = p2testandinc(c);
sed 's/:.*//' /etc/passwd > /tmp/X1 sort < /tmp/X1 > /tmp/X2 uniq -u < /tmp/X2 > usernames
ls *rcand gets the following output:
runcomrc trailrc gleeprcHe knows that he has two other files with names that end in rc, namely .cshrc and .exrc. He wonders why the command did not print them. Explain why. What command should he have given to list all files ending in rc, even those which begin with a "."?