Linked List

July 9, 2010 at 12:47 am | Posted in Uncategorized | Leave a comment

This week in class we learned about linked lists. What is a linked list? A linked list is a chain of structs or records called nodes.A node refers to one item in a linked list. Each nodes has at least 2 members. One which points to the next item or node in the list.
Advantages

  • Can start with space for just one element allocated and then add on new elements easily without the need to do any copying and reallocation whereas in an array you must allocate memory for certain number of elements.
  • Inserting or deleting nodes from a linked list is easy at any place of the linked list.

The const Modifier

June 18, 2010 at 6:04 pm | Posted in Uncategorized | Leave a comment

The keyword const in front of a variable definition indicates that the contents of the variable are constant and may not be changed. Since it cannot be changed later, it must be initialized when it is declared.

When it comes to pointers, the const keyword can be in different spots depending on whether you want the pointer to be constant or the location that it points to to be constant.
ex. const char *str;
or
int *const p = &n;

The second example indicates that p points to the variable n, and cannot point anywhere else.

Generic Pointers

June 5, 2010 at 5:44 pm | Posted in Uncategorized | Leave a comment

This week we learned that void * can be used to store an address when we don’t care what kind of data it’s being pointed to. They come in handy when you want a pointer to point to data of different types at different times.

Here’s an example taken from http://www.faqs.org/docs/learnc/x658.html

int
main()
{
int i;
char c;
void *the_data;

i = 6;
c = ‘a’;

the_data = &i;
printf(“the_data points to the integer value %d\n”, *(int*) the_data);

the_data = &c;
printf(“the_data now points to the character %c\n”, *(char*) the_data);

return 0;
}

Lazy Evaluation

May 29, 2010 at 1:02 pm | Posted in Uncategorized | Leave a comment

In this week’s class we learned about lazy evaluation. It is the technique of delaying a computation until the result is required.
Benefits

  • Speeds creation/initialization time
  • Saves memory by not creating things until they are needed

Example
int a = 2;
int b = 4;

if (b<1 && (a = a + 3))
printf("Z\n");
printf("%d, a);

This program will output 2. As b< 1 is false the whole condition's result is known, the second part of the evaluation (a = a + 3) therefore never gets executed.

Console I/O for Borland C/C++ Compilers

May 21, 2010 at 9:08 pm | Posted in Uncategorized | Leave a comment

When using the Borland C/C++ compiler you must include the header file <conio.h> This will enable you to call the functions that will let you communicate with the console.

Functions

  • void clrscr(void)- clears the screen and leaves the cursor in the upper left-hand corner.
  • void gotoxy(int x, int y) – moves the cursor to the column number x and row number y.
  • int putch(int c)- displays character c at current cursor position and advances 1 position.
  • int cputs(char *s) – displays string s, starting at current cursor position and advances as each character is displayed.
  • int getch(void) – returns a key code for next key pressed. If the key is a standard ASCII key then ASCII code is returned, otherwise the function returns 0.
  • void gettextinfo(struct text_info *r)- fills the struct point to by r with information from screen.

Hello!

May 13, 2010 at 7:44 pm | Posted in Uncategorized | 1 Comment

Hi everyone, this is my first blog. It will contain material covered in OOP 344.

Blog at WordPress.com.
Entries and comments feeds.