Basic Introduction to Programming with C - UCF Study Union ...



Study Union: Spring 2020 Supplemental Instruction COP 3223C (Dr. Tovstolis) w/ Alan :)If you were able to come to the review session please fill out this quick survey for feedback so I can improve in the future! I worked very hard on this review! that we will cover: Basic Introduction to Programming with CHow is C different to that of other languages?Who are the creators of the C language and what did they make with it?How does the computer read code similar to how we read as humans?Where does it start reading and stop?Relationship between chapters and functions?Relationship the termination of sentences in C and reading?What can you make with the C language? Preprocessor Header What are preprocessor Headers?#include <stdio.h> #include <stdlib.h>Int main(void)/int main()What is it?What is the primary purpose?What should it return?VariablesTypes of variablesLimits to variablesHow variables are stored in the memoryGlobal variablesFormat specifiersWhat do format specifiers do?What are the different format specifiers depending on the type of variable?Scanf() functionWhat is the format of scanfWhat does each argument mean in scanfPrintf()How does it help you output something on the screen?Arguments of printfSpecial CharactersFunctions What are functions?What is the importance of function prototypes?How does it help prevent errors?Return value of a function (type in front of function)How do you store return value of function?How do you pass in arguments?What is void?What are the scope of variables?PointersWhat are pointers?How to declare a pointer?How is it useful in programming?How to dereference a pointer? ArraysWhat are arrays?How do you declare an array?What are strings?The dirty truth about arrays?How do pointers relate to arrays and how can you pass an array to a function? True/False?What is considered true or false?For LoopsHow do you declare a for loop?What is a for loop used for? While LoopsHow do you declare a while loop?What is a while loop used for? If… statements What are if statements used for?How do you declare an if… else chain?If() -> else if() -> elseLogical OR (||) and Logical AND (&&) and Logical NOT (!=)Switch StatementsWhat are switch statements?Declaration of switch statementsCharacters NumbersCan you use switch for strings?Importance of break;Fall through in absence of breakStructuresWhat are structures?Structure Members?Pointer to a structureDereferencing a structure memberBitwise OperatorsHow to turn decimal into Binary?How to turn in binary into Decimal?AND Operator (&)OR Operator (|)XOR Operator (^)NOT Operator (~)Table of Contents TOC \o "1-3" \h \z \u Basic Introduction to Programming with C PAGEREF _Toc37800691 \h 6Preprocessor Header PAGEREF _Toc37800692 \h 7Int main(void)/int main() PAGEREF _Toc37800693 \h 7Variables PAGEREF _Toc37800694 \h 8Exercise: PAGEREF _Toc37800695 \h 9Solution: PAGEREF _Toc37800696 \h 9Format specifiers PAGEREF _Toc37800697 \h 10Scanf() function PAGEREF _Toc37800698 \h 11Printf() PAGEREF _Toc37800699 \h 12Exercise: PAGEREF _Toc37800700 \h 12Solution: PAGEREF _Toc37800701 \h 13Functions PAGEREF _Toc37800702 \h 14Exercise: PAGEREF _Toc37800703 \h 15Solution: PAGEREF _Toc37800704 \h 16Pointers PAGEREF _Toc37800705 \h 17Exercise: PAGEREF _Toc37800706 \h 18Solution: PAGEREF _Toc37800707 \h 19Arrays PAGEREF _Toc37800708 \h 20Exercise: PAGEREF _Toc37800709 \h 21Solution: PAGEREF _Toc37800710 \h 22Exercise 2: PAGEREF _Toc37800711 \h 22Solution: PAGEREF _Toc37800712 \h 23True/False? PAGEREF _Toc37800713 \h 24For Loops PAGEREF _Toc37800714 \h 24Exercise: PAGEREF _Toc37800715 \h 25Solution: PAGEREF _Toc37800716 \h 25While Loops PAGEREF _Toc37800717 \h 26Exercise: PAGEREF _Toc37800718 \h 27Solution: PAGEREF _Toc37800719 \h 28If… else statements PAGEREF _Toc37800720 \h 28Exercise: PAGEREF _Toc37800721 \h 29Solution: PAGEREF _Toc37800722 \h 30Switch Statements PAGEREF _Toc37800723 \h 30Exercise: PAGEREF _Toc37800724 \h 31Solution: PAGEREF _Toc37800725 \h 32Structures PAGEREF _Toc37800726 \h 32Exercise: PAGEREF _Toc37800727 \h 33Solution: PAGEREF _Toc37800728 \h 34Bitwise Operators PAGEREF _Toc37800729 \h 34 PAGEREF _Toc37800730 \h 37References/Useful Links PAGEREF _Toc37800731 \h 38Table of Figures TOC \h \z \c "Figure" Figure 1: Types of Variable with Ranges PAGEREF _Toc37800652 \h 8Figure 2: ASCII - American Standard Code for Information Exchange PAGEREF _Toc37800653 \h 8Figure 3: Format Specifiers PAGEREF _Toc37800654 \h 10Figure 4: Special Characters PAGEREF _Toc37800655 \h 11Figure 5: Array Pictorial Representation PAGEREF _Toc37800656 \h 21Figure 6: For Loop Pictorial Representation PAGEREF _Toc37800657 \h 24Figure 7: While Loop Pictorial Representation PAGEREF _Toc37800658 \h 26Basic Introduction to Programming with CHow is C different to that of other languages?Unlike other languages, C is a very low-level language that you basically have to give all the instruction that it has to do. Additionally, it is a static language unlike a dynamic language, once you set the variable type it has to stay that type throughout the entirety of the code. ***** Important C is case sensitive so int race_car1; is different than Race_car1;Who is the creator of the C language and what did he/she make with it?The creator the C language is Dennis Ritchie. He made in 1972 in the Bell Telephone laboratories. He used it to create the UNIX operating system and B language with Ken Thompson. How does the computer read code similar to how we read as humans?Where does it start reading and stop?Relationship between chapters and functions?Relationship the termination of sentences in C and reading?The computers reads code similar to how humans read a book. The computer reads code from left to right and from top to bottom. The computer starts reading code from intmain() and moves to other functions in chronological order similar to how humans start reading from chapter 1 and move on to subsequent chapters in chronological order. The termination of a “sentence” in code ends with a semicolon (;) while sentences in reading end with a period (.)What can you make with the C language?The C language is used to make operating systems like Mac OS and basically any UNIX based operating systems like Ubuntu or Devian. It is also used to make basic programs on the computer like Kindle Books, VLC, etc. Additionally, it is also used to make executable files which can be a bad thing (viruses). Preprocessor Header What are preprocessor Headers?#include <stdio.h>#include <stdlib.h>Preprocessor is basically a process which tells the compiler to do pre-processing before the actual compiling. Headers are basically files that the computer finds reads and processes and essentially replaces where you put the #include. When you download a compiler for C it will already have header files which will have many widely used functions. #include <stdio.h> stands for standard input and ouput; this will have functions like scanf(), printf(), fseek(), etc. #include <stdlib.h> stands for standard library; this will have functions like malloc(), free(), rand()Int main(void)/int main()What is it?What is the primary purpose?What should it return?int main() is the first function that the compiler will go to after doing all preprocessor commands and defining constants. int main(void) and int main() are the same thing. What is inside of the parentheses are the arguments of the function so leaving it blank means no arguments and putting void essentially means get rid off so it also means no arguments. The primary purpose of int main() is that it gives a unified place where code starts for everyone like Chapter 1 is the first chapter that you start on. At the end of int main() it should return 0 which basically tells the program to end and that the program ran successfully. VariablesTypes of variablesLimits to variablesHow variables are stored in the memoryGlobal variables62230117475006223024130Figure SEQ Figure \* ARABIC 1: Types of Variable with Ranges0Figure SEQ Figure \* ARABIC 1: Types of Variable with Ranges INCLUDEPICTURE "" \* MERGEFORMATINET Figure SEQ Figure \* ARABIC 2: ASCII - American Standard Code for Information ExchangeVariables are not just stored randomly in the memory! They are stored in specific places of your computer’s memory. You can access those places in the memory with pointers. Global Variables are defined in the preprocessor #define HELLO 1. It is good programming practice to define them through all uppercase letters. Each character actually corresponds to a decimal number so you can actually use characters and numbers Interchangeably. Characters are defined in the following way: char name = ‘C’;Exercise:Print out the decimal value of the char ‘A’ in programming. Solution:#include <stdio.h> int main() {char name = 'A';printf("%d", name);return 0;}Format specifiersWhat do format specifiers do?What are the different format specifiers depending on the type of variable?Format specifiers basically define the type of variable to be acquired on the standard input/ouput for specific functions. For certain functions, you the computer needs to know the type and you pass in those variables through format specifiers. Ex. Scanf() and printf().Figure SEQ Figure \* ARABIC 3: Format SpecifiersScanf() functionWhat is the format of scanf()What does each argument mean in scanf()The format of scanf() is scanf(“ %s”, &Variable);The first argument of scanf is the type of variable that you will be passing through, the second argument is the variable’s address where the computer needs to store the input into that variable.Printf()How does it help you output something on the screen?Arguments of printfSpecial CharactersThe format of printf() is printf(“Hello my name is %d”, variable);The first argument is what you are printing with format specifiers which will get replaced by variables that you pass through. INCLUDEPICTURE "" \* MERGEFORMATINET Figure SEQ Figure \* ARABIC 4: Special CharactersExercise:What is the output of this code? What is wrong with this code? #include <stdio.h> int main() {char favorite_letter;char second_favorite_letter;printf("What is your favorite letter?\n"); scanf("%c", &favorite_letter);printf("What is your second favorite letter?\n");scanf("%c", &second_favorite_letter);printf("Your favorite letter is %c. Your second favorite letter is %c", favorite_letter, second_favorite_letter);return 0;}Solution:Special Characters! The code will only output the user’s favorite letter and not the second favorite letter. The enter key actually has a special character that is associated with it -> newline (\n). In the code, it first asks the user for their favorite letter, the user enters their favorite number and then clicks the enter key. The enter key is now in the buffer (place in the computer where all the inputs of the user reside), now when the code asks for the user’s second favorite letter the enter key which still resides the buffer will get stored in the second_favorite_letter variable. Therefore, the second_favorite_letter will store “\n”. To fix this issue you can actually tell the scanf() to ignore incoming whitespace (newline (\n), tab (\t) and spaces). By formatting scanf() in this way: scanf(“ %c”, &variable);This is the way that most good programmers use scanf() and it’s good programming practice. They always format their scanf with a space before their format specifier. Fixed Code:#include <stdio.h> int main() {char favorite_letter;char second_favorite_letter;printf("What is your favorite letter?\n"); scanf(" %c", &favorite_letter);printf("What is your second favorite letter?\n");scanf(" %c", &second_favorite_letter);printf("Your favorite letter is %c. Your second favorite letter is %c", favorite_letter, second_favorite_letter);return 0;}An alternate method is to write a variable which will store the incoming whitespace in this way: scanf(“%c”, &favorite_letter);scanf(“%c”, &enter_key);scanf(“%c”, &second_favorite_letter);The only problem with this format is that it will only work if the only whitespace that they input is the enter key after entering the favorite letter. If they input the space bar and then the enter key for favorite letter it will not work (the space bar will get stored in enter_key and the enter key will get stored in second favorite letter. Functions What are functions?What is the importance of function prototypes? How does it help prevent warnings?Return value of a function (type in front of function)How do you store return value of function?How do you pass in arguments?What is void?What are the scope of variables?A function is basically a group of statements that are all consolidated together in chronological order in order to accomplish a certain task or return something at the very end. In Programming with C, functions should be declared before the call of any functions. The way that C works is that after doing all preprocessor instructions it will automatically start looking for the intmain() function. Now when you call a function in intmain() without having previously declared it doesn’t understand what that function is since it has no previous knowledge of the function. That’s why some compilers will give you an error without function prototypes. Don’t worry though function prototypes are easy to create! All you have to do is program that you usually do and at the very end put the functions that you used with the return type and arguments at the top of your code after the preprocessor commands. It’s easy and it’s good programming practice!The return type of the function is what type of variable will be returned back into the function that you called it from. What gets returned back can be stored into a variable as long as you set it equal to the function that you call. For example: my_var = my_function(my_argument_1, my_argument_2). Recusion is the process where you call the same function within the same function and end the cycle until a certain condition is met. Arguments are easily passed into the function in the format shown above my_var = my_function(my_argument_1, my_argument_2). Void is basically the same thing as leaving the arguments that you are passing through blank void essentially means no arguments. Exercise:Create a function prototype for the following code:What would happen if you tried to use the variable declared in int main() in ice_cream_function()? #include <stdio.h> int main() {int vanll_ice_creams;int choc_ice_creams;int total;printf("How many vanilla ice creams did you eat yesterday?\n");scanf(" %d", &vanll_ice_creams);printf("How many chocolate ice creams did you eat yesterday?\n");scanf(" %d", &choc_ice_creams);total = ice_cream(vanll_ice_creams, choc_ice_creams);printf("You ate a total of %d ice creams. Stop eating so much ice cream and eat some spinach instead!", total);return 0;}int ice_cream(int vanilla, int chocolate) { int sum; printf("You ate %d vanilla ice creams!\n", vanilla); printf("You ate %d chocolate ice creams!\n", chocolate); sum = vanilla + chocolate; return sum;}Solution: #include <stdio.h> int ice_cream(int vanilla, int chocolate);int main() {int vanll_ice_creams;int choc_ice_creams;...return 0;}int ice_cream(int vanilla, int chocolate) { int sum; ... return sum;}PointersWhat are pointers?How to declare a pointer?How is it useful in programming?How to dereference a pointer? Pointers are special variables that hold the memory addresses of other variables. Why should you care? Having the memory address of another variable can actually be very useful in programming. For one, as we’ll see in the “Arrays” section you can’t actually pass through a whole array at once in programming. Instead you have to pass through the pointer which holds the memory address of the array. You can also change the value of a specific variable in other functions which you couldn’t do otherwise. In order to declare a pointer, you have to declare what type of variable it will be pointing to for example (if it’s going to point to an integer value) the ampersand refers to the memory address of the variable that it’s going to point to:int * my_pointer = &variable; Good programming practice dictates that when you declared pointers, they have a capital ‘P’ before the variable name in order to indicate that it is a pointer: int * PvariableDereferencing a pointer refers to getting the value of the variable that the pointer is pointing to. In order to deference a variable if the pointer “Pvariable” was pointing to variable x. It would be dereferenced in this way:*(Pvariable)Exercise:Make a pointer that points to the variable that refers to the number of vanilla ice creams. Use this to dereferenced pointer to print out the value of the variable. Also use this pointer to change the value of the vanialla variable in the ice_cream function. Change it to 25.#include <stdio.h> int ice_cream(int vanilla, int chocolate);int main() {int vanll_ice_creams;int choc_ice_creams;int total;printf("How many vanilla ice creams did you eat yesterday?\n");scanf(" %d", &vanll_ice_creams);printf("How many chocolate ice creams did you eat yesterday?\n");scanf(" %d", &choc_ice_creams);total = ice_cream(vanll_ice_creams, choc_ice_creams);printf("You ate a total of %d ice creams. Stop eating so much ice cream and eat some spinach instead!", total);return 0;}int ice_cream(int vanilla, int chocolate) { int sum; printf("You ate %d vanilla ice creams!\n", vanilla); printf("You ate %d chocolate ice creams!\n", chocolate); sum = vanilla + chocolate; return sum;}Solution:#include <stdio.h> int ice_cream(int vanilla, int chocolate, int * Pvanilla2);int main() {int vanll_ice_creams;int choc_ice_creams;int total;int * Pvanilla; Pvanilla = &vanll_ice_creams;printf("How many vanilla ice creams did you eat yesterday?\n");scanf(" %d", &vanll_ice_creams);printf("You ate %d vanilla ice creams!\n", *(Pvanilla));printf("How many chocolate ice creams did you eat yesterday?\n");scanf(" %d", &choc_ice_creams);total = ice_cream(vanll_ice_creams, choc_ice_creams, Pvanilla);printf("You ate %d vanilla ice creams now!\n", vanll_ice_creams);printf("You ate a total of %d ice creams. Stop eating so much ice cream and eat some spinach instead!", total);return 0;}int ice_cream(int vanilla, int chocolate, int * Pvanilla2) { int sum; *(Pvanilla2) = 25; sum = vanilla + chocolate; return sum; }ArraysWhat are arrays?How do you declare an array?What are strings?The dirty truth about arrays?How do pointers relate to arrays and how can you pass an array to a function? Arrays are data structures of contiguous blocks of memory that hold the same type of variable in each of its elements.type arrayName[arraySize];An integer array is declared like this:int array[5] = {5,8,4,2,7};OR... int array[]; Strings are actually just an array of characters grouped together like this:char name[5] = “Alan”; OR... char name[];Each string ends with a special character “\0” which is the null character which indicates the end of the string. So in reality, the array for char name[5] is stored as “Alan\0.” That’s why the array size is 5 instead of 4 to take into account the null character \0.In order to change the value of a character array mid-code you have to change it using the built-in function (<string.h>). strcpy(destination, what will be copied);Each element of an array has an index or number corresponding to it. The index starts counting from zero such that in the example above index 0 corresponds to the number 5 but index 3 corresponds to the number 4. You can access each element through the following:array[0] would hold the value 5 & array[3] would hold the value 4.The dirty truth about arrays is that they are actually disguised as pointers. Believe it or not array is actually a pointer to the memory address to the first element of the array.&array[0] is equivalent to (array) AND, array[0] is equivalent to *(array+0)&array[1] is equivalent to (array+1) AND, array[1] is equivalent to *(array+1)&array[2] is equivalent to (array+2) AND, array[2] is equivalent to *(array+2)&array[3] is equivalent to (array+3) AND, array[3] is equivalent to *(array+3)...You can’t actually pass a whole array through a function so you pass the memory address of the first element of the array in the argument of the function. This has two dual benefits 1. You have the memory address of each element of the array.2. You have and can change the value of element of the array by dereferencing the array pointer.1102995102552511029951025525Figure SEQ Figure \* ARABIC 5: Array Pictorial RepresentationFigure SEQ Figure \* ARABIC 5: Array Pictorial Representation11033256598200Exercise: What is wrong this code?What can you do to fix it?#include <stdio.h> int main() {char name[99];printf("What is your full name?\n"); scanf("%s", name);printf("Your full name is %s", name);return 0;}Solution:The code will actually think the spacebar is the end of the string so therefore it will only get the first name and not the last. Thus, you should split it up between two strings such that it will be in terms of first and last name. int main() {char first_name[99];char last_name[99];printf("What is your first and last name?\n"); scanf(" %s", first_name);scanf(" %s", last_name);printf("Your full name is %s", name);return 0;}Exercise 2: Pass the pointer of the array to function, and then change the value of the 4th index to 65. Then print out that value in intmain() #include <stdio.h> int changearray(int * Parray);int main() {int array[5] = {5,8,4,2,7};printf("The value of index 4: array[4] = %d\n", array[4]);// WRITE CODE HEREprintf("The value of index 4: array[4] = %d\n", *(array+4));return 0;}int changearray(int * Parray) { // WRITE CODE HERE return 0;}Solution:#include <stdio.h> int changearray(int * Parray);int main() {int array[5] = {5,8,4,2,7};printf("The value of index 4: array[4] = %d\n", array[4]);changearray(array);printf("The value of index 4: array[4] = %d\n", *(array+4));return 0;}int changearray(int * Parray) { *(Parray+4) = 65; return 0;} True/False?What is considered true or false?In programming with C anything that consist of the following or the like is considered False:1. NULL2. Boolean type is equal to false3. 0 Anything that doesn’t belong to this type is trueAny set of string valuesAny decimal value Any set of character valuesFor LoopsHow do you declare a for loop?What is a for loop used for? The declaration for a for?loop is: for (initialization; condition; increment) {code;}The for loop is mostly used when you have a set amount of times that you want to run the same piece of code multiple times in a row.Figure SEQ Figure \* ARABIC 6: For Loop Pictorial RepresentationExercise:Print the value of variable ‘z’ from 64 to 69 using a for loop with a newline in between.Solution:#include <stdio.h>int main() { int z; for(z=64; z<=69; z++) { printf("Value of z: %d \n", z); } return 0;}While LoopsHow do you declare a while loop?What is a while loop used for?The declaration for a while loop is: while(condition) {code;}The while loop is mostly used when you have a code that you want to run as long as a certain condition is met. 165798511112500 -180340342339Figure SEQ Figure \* ARABIC 7: While Loop Pictorial Representation0Figure SEQ Figure \* ARABIC 7: While Loop Pictorial RepresentationExercise: Print the value of variable ‘z’ from 64 to 69 using a while loop with a newline in between. Same as the for loop exercise but this time it’s with a while loop.Solution:#include <stdio.h>int main() { int z = 64; while(z<69) { printf("Value of z: %d \n", z); z++; } return 0;}This shows that you can essentially do the same thing for the for loop with a while loop for the majority of cases! It’s up to you really! If… else statements What are if statements used for?How do you declare an if… else chain?If() -> else if() -> elseLogical OR (||) and Logical AND (&&) and Logical NOT (!=)If statements are one of the most used and important functions in programming. They are essentially found anywhere. All it is really is... if this is true then do this. Else if this is true then do this instead. If the if statement or all of the previous conditions for the else if statements are not true then it will run the last statement the else statement. if() -> elseif() -> elsePlease note that the else statement case doesn’t have a condition to check as it’s anything else left out by the conditions.To check if something is equal to something use: ==If you want either or of the conditions to be true for a true output use: || in between both of the conditionscondition1 || condition 2If you want both of the conditions to be true for a true output use: && in between both of the conditionscondition1 && condition2If you want the condition to be false for a true output use: != condition1 != statementExercise: Make a program using the chain of if()... elseif()... and else. Ask the user to input their GPA (use floats) and if they have done their programming homework (use y/n).If the person has a GPA >= 3.0 and they have done their programming homework, then the output is: “You have become one with the force.” If the person has a GPA >= 3.0 or they have done their programming homework, then the output is: “You need more training.” If the person has not done either, then the output is: “You have not become one with the force.”Solution:#include <stdio.h>int main() { float GPA; char prog_hw; printf("What is your GPA?\n"); scanf(" %f", &GPA); printf("Did you do your programming homework? (y/n) \n"); scanf(" %c", &prog_hw); if(GPA >= 3.0 && prog_hw == 'y') { printf("You have become one with the force\n"); } else if(GPA >= 3.0 || prog_hw == 'n') { printf("You need a little bit more training.\n"); } else { printf("You have not become one with the force."); } return 0;}Switch StatementsWhat are switch statements?Declaration of switch statementsCharacters NumbersCan you use switch for strings?Importance of break;Fall through in absence of breakSwitch statements are most useful when you have to compare a variable/value to multiple different values and have to do something different for each of those values.They only work for integral or enumerated types i.e. characters or integer valuesThey cannot work for strings and floatsSwitch statements are declared like this:switch(variable/value) { case value1: code1; break; case value2: code2; break; default: code3;}The break statement tells the switch where to stop running the code, in the absence of a break statement it will “fall through” and do the code for the next cases until it encounters. In the example above if the variable/value matched up to value1 it would start running the code1 but stop right after encountering the break statement. If that statement was absent it would run code1 and code2 even though the variable/value doesn’t match up to value2 until it encountered the break and stop, this is call “falling through.” The default case is when the variable/value doesn’t match up to any of the cases.Exercise:Ask the user to input their letter grade into a character variable. Then have a switch statement compare the value of the character variable with different cases. For a grade letter of A and B have one of them fall through to the next case such that it will output: “Excellent Work!” For a letter grade of C, output: “Try to study a little more.” For a letter grade of D and F, output: “Come to SI!” For the default case output: “Invalid Grade.” Solution:#include <stdio.h> int main () { char grade = 'B'; printf("What is your letter grade?\n"); scanf(" %c", &grade); switch(grade) { case 'A' : case 'B' : printf("Excellent Work!\n"); break; case 'C' : printf("Try to study a little more.\n" ); break; case 'D' : case 'F' : printf("Come to SI!\n" ); break; default : printf("Invalid grade.\n" ); } return 0;}StructuresWhat are structures?Members of a structuresPointer to a structureDereferencing a structureA structure is a data type created by the user which has the ability to consolidate many different types of variables all into one overarching data type.The programmer creates the many different types of variables into the overarching data type called members. The declaration of a structure usually occurs before intmain () and follows:struct [structure tag] { member definition; member definition; ... member definition;} ; Once you have defined the following before intmain(), you create variables just like int x or char c. In the following way struct [structure tag] my_var; my_var will now have all the members that you have defined previously. Those members can be accessed through a period like this => my_var.member Advanced use of structs:You can create a pointer that will point to the memory address of you new variable struct and will be defined by struct [structure tag] * pvar = &my_var.To dereference the a pointers members it is through the following:pvar->memberExercise: A start-up university called UCF is admitting a lot of new students. It wants the ability to store all of the new student data in a way that is easy and practical. Use Structures such that it will have a student’s name, ID #, GPA. Create a fictional students to see if your structures worked and output using the members of the newly created structure variable.Solution:#include <stdio.h>#include <string.h> struct student { char name[50]; int ID; float GPA;}; int main( ) { struct student student1; strcpy(student1.name, "Tuna Fish"); student1.ID = 12345; student1.GPA = 3.4; printf("Student's Name: %s\n", student1.name); printf("Student's ID: %d\n", student1.ID); printf("Student's GPA: %f\n", student1.GPA); // ADVANCED USERS (Using pointers to access members) struct student *pstudent1 = &student1; printf("Student's Name: %s\n", pstudent1->name); printf("Student's ID: %d\n", pstudent1->ID); printf("Student's GPA: %f\n", pstudent1->GPA); return 0;} Bitwise OperatorsHow to turn decimal into Binary?How to turn in binary into Decimal?AND Operator (&)OR Operator (|)XOR Operator (^)NOT Operator (~)05397500-17033023397900-304800000-30543520256500-8128038004750026670000References/Useful Links ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download