Example code:
#include <stdio.h> int main() { int number; printf("Please enter a number between 1 and 10: "); scanf("%d", &number); //here is the selection statement if (number < 5 && number >= 1) { printf("You entered a number between 1 and 4\n"); } else if (number >=5 && number <=10) { printf("\nYou entered a number between 5 and 10\n"); } else { printf("\nYou entered an invalid number.\n"); } return 0; }
Example code:
#include <stdio.h> int main() { int number = 10; int x; printf("\n"); for(x = 1; x <= number; x++) { printf("%d\n", x); } return 0; }
File access was covered in Sys prog.
Doubled linked lists are not much different than linked lists except now each node not only points to the next node but to the previous as well.
A stack is a last in first out data structure, meaning the “top” of the stack is all you have immediate access to. You can store data on top of the stack, remove it, or view it.
Pushing is when you add to the top of a stack or initializes the stack if it is empty
Popping simply removes the data stored at the top of the stack.
Top typically simply returns the value at the top of the stack but does not delete it like pop does.
Overflow is when a stack is full and cannot accept anymore data
Underflow is when the stack is empty and there is no data to be removed
LIFO means last in first out. Whatever the last thing that was stored will be the first one out. As stated before stacks are LIFO
FIFO means first in first out. Whatever the first thing that was stored will be the first one out. Queues(which will be discusses later) are FIFO
A queue is a first in first out data structure. Where with a stack you could only add or remove from the top, with a queue you add to the top(or back, depending on if you like to envision a queue as a sideways stack) but you remove from the bottom(front).
Enqueuing is a queues version of pushing. You simply add new data to the “end” of whatever type of queue you are using.
Dequeuing is the process of removing the FIRST thing that was stored in your queue, unlike a stack where the last thing stored is removed.
Overrun(queue overflow) occurs when you try to add data onto a queue that is full Underrun(queue underflow occurs when you trying to remove data from a queue that is empty
Identification and definition of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Identification and definition of the chosen keyword. Substitute “keyword” with the actual keyword.
If you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Everything in unix is a file and that includes any device on the system. Depending on the device, device files can be written to and read from just like any other file. The monitor device file can be written to but not read from. A keyboard can be read from but not written to.
A race condition is when multiple processes are able to access shared data and they try to change it at the same time. It is called a race condition because the result is depending on the timing of events. page 149 of understanding unix/linux programming has a good example.
An atomic operation is when the kernel joins two or more system calls into one indivisible unit. Meaning the entire sequence of calls has to be performed or none at all. Page 150 of understanding unix/linux programming talks briefly about it.
The STREAMS model of data flow and connection attributes allows for modularity of processing. You can write or remove modules as you see fit.
Blocking is when a call waits for input. If there is no input then the program waits for it. Non-Blocking is when when blocking is turned off thus if there is no input the program will still continue.
A Signal can be defined as a one word message sent by the kernel. Each signal has a numerical code. Requests for signalcs can come from processes, exceptions and user keystrokes. Many signals cause processes to die, but there are other types of signals. You can typically find the list of signals in /usr/include/signal.h
What is the difference between a structure and a class?
How are data structures allocated and used in memory?
Just like any variable type data structures are given a memory address. Data structures typically have nodes and each node has its own address, this is done in C with the malloc() function.
State the course objective; define what that objective entails.
State the method you will use for measuring successful academic/intellectual achievement of this objective.
Follow your method and obtain a measurement. Document the results here.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
Design a program that handles signals.
#include <signal.h> #include <stdio.h> void intu(); void seg(); int main() { char *array; signal(SIGINT, intu); //interrupt aka ctrl c signal(SIGSEGV, seg);// good ol seg fault why is it V instead of F? getchar(); printf("%c\n", *array);// why does this continue to segment? return 0; } void intu() { printf("You tried to interrupt me but I won't let you!\n"); } void seg() { printf("I segmented!\n"); }
When defining a struct, can you give a value to any variables within the struct? If not, then why not?
Below is the code I attempted to compile:
#include <stdio.h> struct list { int variable = 57; }; int main() { /*struct list fashizzle; fashizzle.variable = 10; printf("\nThe variable is %d\n", fashizzle.variable);*/ return 0; }
Here is what happens when attempting to compile:
lab46:~/Desktop/experiments$ gcc -Wall structvar.c structvar.c:7: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token lab46:~/Desktop/experiments$
So the answer to the question is: No you cannot give value to a variable when defining a struct.
The reason for this is quite simple, as I have stated in previous parts of my opus a variable is simply a human name given to an address. When you are defining a structure, you are not assigning an address yet, that does not happen until you actually declare a structure in the main program. At that point a memory address is given and now you can give it a name and store a value.
After learning about enum I was curious as to what value it starts at, is it 0 or 1? Or possibly some other random value?
Here is my code:
#include <stdio.h> int main() { enum days{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; printf("%d\n", sunday); printf("%d\n", monday); return 0; }
Here is the output:
lab46:~/Desktop/experiments$ ./a.out 0 1 lab46:~/Desktop/experiments$
It would appear that the default for enum is to start at 0
I was curious if enumerated values would still allow you to math operators. Basically I am going to take an enumerated variable and see if I can add one and get the next enumerated variable.
Using the same code in previous experiment except instead of printing Monday, I will try to print sunday + 1
#include <stdio.h> int main() { enum days{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; printf("%d\n", sunday); printf("%d\n", sunday+1); return 0; }
Here is the output:
lab46:~/Desktop/experiments$ ./a.out 0 1 lab46:~/Desktop/experiments$
As we can see it worked the same way as the previous experiment meaning enumerated variables can still have math ops used on them.