All questions
- What are the advantages and disadvantages of a heap? Storing data on the heap is slower than it would take when using the stack. However, the main advantage of using the heap is its flexibility... 1
- How do you convert strings to numbers in C? You can write you own functions to do string to number conversions, or instead use C’s built in functions. You can use atof to convert to a... 1
- Create a simple code fragment that will swap the values of two variables num1 and num2. int temp; temp = num1; num1 = num2; num2 = temp; 2
- What is the use of a semicolon (;) at the end of every program statement? It has to do with the parsing process and compilation of the code. A semicolon acts as a delimiter, so that the compiler knows where each st... 1
- What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler The most probable reason behind this error is that the header file for that function was not indicated at the top of the program. Header fil... 1
- How do you generate random numbers in C? Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0,... 1
- What is wrong in this statement? scanf(“%d”,whatnumber); An ampersand & symbol must be placed before the variable name whatnumber. Placing & means whatever integer value is entered by the user is s... 1
- Write a loop statement that will show the following output: 1 12 123 1234 12345 Use two nested for loops: the outer loop picks the row number, and the inner loop prints 1 up to that row number, followed by a new line. #i... 1
- What is the advantage of an array over individual variables? When storing multiple related data, it is a good idea to use arrays. This is because arrays are named using only 1 word followed by an eleme... 1
- What is the significance of an algorithm to C programming? Before a program can be written, an algorithm has to be created first. An algorithm provides a step by step procedure on how a solution can... 1
- What are compound statements? Compound statements are made up of two or more program statements that are executed together. This usually occurs while handling conditions... 1
- when is the “void” keyword used in a function? When declaring functions, you will decide whether that function would be returning a value or not. If that function will not return a value,... 1
- Why is it that not all header files are declared in every C program? The choice of declaring a header file at the top of each C program would depend on what commands/functions you will be using in that program... 1
- Can two or more operators such as \n and \t be combined in a single line of program code? Yes, it’s perfectly valid to combine operators, especially if the need arises. For example: you can have a code like ” printf (“Hellonn\’Wor... 1
- Can I use “int” data type to store the value 32768? Why? No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “long int” instead. You can also use “uns... 2
- How do you access the values within an array? Arrays contain a number of elements, depending on the size you gave it during variable declaration. Each element is assigned a number from 0... 1
- What are variables and it what way is it different from constants? Variables and constants may at first look similar in a sense that both are identifiers made up of one character or more characters (letters,... 1
- What is syntax error? Syntax errors are associated with mistakes in the use of a programming language. It maybe a command that was misspelled or a command that mu... 1
- What are header files and what are its uses in C programming? Header files are also known as library files. They contain two essential things: the definitions and prototypes of functions being used in a... 1
- Can the curly brackets { } be used to enclose a single line of code? While curly brackets are mainly used to group several lines of codes, it will still work without error if you used it for a single line. Som... 1
- How do you declare a variable that will hold string values? The char keyword can only hold 1 character value at a time. By creating an array of characters, you can store string values in it. Example:... 1
- Compare and contrast compilers from interpreters. Compilers and interpreters often deal with how program codes are executed. Interpreters execute program codes one line at a time, while comp... 1
- Which of the following operators is incorrect and why? ( >=, <=, <>, ==) <> is incorrect. While this operator is correctly interpreted as “not equal to” in writing conditional statements, it is not the proper oper... 1
- What is a nested loop? A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner loop that is inside an outer loop. In this... 1