>lol Stack Overflow is cheating
Yes, but cheating in a good way.
>lol Stack Overflow is cheating
Yes, but cheating in a good way.
My best code is written with the delete key.
Regarding Example 1.4:Code:#include <stdio.h> int main() { int n[5] = {1,2,3,4,5}; int *ptr; /* points to n[0]*/ ptr = &n[0]; printf("ptr now points to n[%d] whose value is %d\n", (int)(ptr - n), *ptr); /* points to n[1] */ *(ptr+1); /* this expression references n[1], but ptr remains the same */ printf("ptr now points to n[%d] whose value is %d\n", (int)(ptr - n), *ptr); /* points to n[2] */ (*ptr)++; /* this increments what ptr is pointing to, and ptr remains the same */ printf("ptr now points to n[%d] whose value is %d\n", (int)(ptr - n), *ptr); /* However, increments the value of the content of the location pointed by ptr */ ++*ptr; printf("ptr now points to n[%d] whose value is %d\n", (int)(ptr - n), *ptr); return 0; } /* my output ptr now points to n[0] whose value is 1 ptr now points to n[0] whose value is 1 ptr now points to n[0] whose value is 2 ptr now points to n[0] whose value is 3 */
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Alright,
Thanks guys. I will edit my original post and make the necessary changes.
Though, I had a late night last night and started to slip up on my presentation. My apologies. I occasionaly fix stuff. Little things I keep skipping over, and adding [color] tags too. Thanks Salem for pointing that out!
Note: All examples have been modified. And can now compile sucessfully with -Wall, -pedantic, -ansi, and -std=c89 GCC compiler flags. Remember, I made a few examples of what not to do, so of course those may return warnings or errors.
- Stack Overflow
Last edited by Stack Overflow; 02-04-2005 at 12:19 PM.
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.