What do you mean by arrays and explain how to create and initialize arrays in C?
Arrays are group or set of variables having the same data type. Arrays can hold different values depending on the values assigned to them.
To create (or declare) an array is somewhat similar to declaring a variable. You must first enter the data type, the array name (you can name your array anything you like), then array size enclosed in square brackets.
Example:
int arrNum[5];
Using the example given above, it shows that we declare an integer array with the size of 5. Five (5) is the total elements in an integer array called "arrNum" So there are 0 to 4 (zero to four) arrNum arrays (array counts must always start at zero). Namely:
int arrNum[0];
int arrNum[1];
int arrNum[2];
int arrNum[3];
int arrNum[4];
You can store different integer values at any element of int ArrNum. But, do not assign a value that is beyond the size of the array. It will give you a logical error.
Example:
arrNum[6] = 95;
arrNum[5] = 20;
On the second example above, it will still give you a logical error. We defined arrNum to have 5 elements (from zero to four). So, arrNum[5] is out of arrNum's size capacity. Also, once we declared an array to have a definite size, it cannot be redefined to have more elements than what is declared.
To initialize an array, you may need to use loops, specifically "for loop". You may do it manually (without using loops) but loops are useful with arrays. For example, we want to initialize all elements of arrNum[5] to zero:
int Counter = 0;
int arrNum[5];
for (Counter = 0; Counter < 5; Counter++)
{
arrNum[Counter] = 0;
}
In the example above, we used a for loop to initialize all elements of int arrNum[5] to zero. The loop will only stop if and only if the counter exceeds 4. We borrow the value of the counter to act as the size of the array.
Meanwhile, in using an array of characters (also called character array or String), the size of the string must be the number of string plus one. Example, you wanted to write Fire as the value of string called "Word":
char Word[5]; // Array declaration
Word[0] = 'F';
Word[1] = 'i';
Word[2] = 'r';
Word[3] = 'e';
Word[4] = '\0';
As you can see, we declared an array that is the number of character more than 1. The last element in a string should be a null value denoted by "\0" (backward slash and zero). This will tell the computer that the string will end and no further character will be added.
Jump Statements
Branching is performed using jump statements, which cause an immediate transfer of the program control. The following keywords are used in jump statements:
What is the minimum number of stacks of size 10 required to implement a queue to size 10?
2 stacks required
Can an for loop be terminated with a semicolon in c language?
Sure.
for (i=0; i
or
i=0; do printf ("%d %s\n", i, argv[i]); while (i++
What do you call it when your running more than one program?
That is called multitasking.
That is called multitasking.
That is called multitasking.
That is called multitasking.
What do you call a stack of straw?
A pile of hay may be called a :
hay bale
The this pointer is an implicit, compiler generated pointer to the current object that a method is manipulating. It is used to differentiate scope between parameters and members, in the case where they have the same name. Example...
class myclass {
...
int data1;
...
mymethod(int data1) {
data1 = data1; /*ambiguous */
this->data1 = data1; /* not ambiguous */
}
...
secondmethod(int data2) {
data1 = data2; /* not ambiguous */
}
...
}
Many coders use some prefix, such as underscore, to mark member variables. This works, but is not necessary.
What are the advantage and disadvantage of the bucket sort?
Adv: BucketSort is an example of a sorting algorithm that runs in O(n). This is possible only because BucketSort does not rely primarily on comparisons in order to perform sorting.
Dis: BucketSort is not useful when scanning the buckets for large arrays which is too costly.
Minimum number of queues needed to implement the priority queue?
Separated queue for every possible priority value.
Is it possible for a function to return more than one value at a time?
No, you can only return one value with a return statement. However, you can return a structure or pointer, so the real answer is yes, though requiring some added complexity.
A set of Rules that define a programming language is called?
The rules of a language is called its syntax.
What is a platform dependent language?
There is no such thing as a platform-free programming language. The correct term is platform-independent language. It simply means that the same source code can be compiled or interpreted upon any platform; the code is not machine-dependent.
What is machine language the the uses and importance?
Machine language is the only language the machine understands. All other languages must be converted to machine code using an assembler, a compiler or an interpreter, depending on whether the source code is written in low-level assembly language or a high-level compiled or interpreted language.
Assemblers and compilers convert the entire source code to machine code whereas interpreters only convert one statement at a time. As a result, interpreted languages do not perform well compared with their compiled and assembled counterparts, but are better suited to testing and debugging high-level algorithms because the code can be executed immediately, there is no need to wait on the assembler or compiler to convert the whole program (which can easily take several minutes).
Java is slightly different to other high-level languages in that it is both compiled and interpreted. However, the Java compiler does not emit machine code like other compilers, it emits Java byte code which is suitable for interpretation by the Java virtual machine. Java is easy to program and highly-portable because the Java virtual machine is consistent across all platforms and the Java byte code is easier to interpret so it performs better than a purely interpreted language. However, it still cannot compete with native machine code programs in terms of performance and resource consumption.
Compilers are easier to work with than assemblers because assembly language requires programs to be written in minute detail at the machine level. Compiled languages incorporate a higher level of abstraction (hence they are high-level) thus you can perform more low-level computations in fewer lines of code. Although some high-level languages such as C and C++ also allow low-level programming through inline assembly, the compiler incorporates optimisers that can take advantage of the machine's hardware to produce machine code that is as efficient if not more efficient than would be possible with assembly language alone.
What are function of flow chart?
Flow charts show a process in steps by connecting them. They are used in designing a process in various fields.
When a piece of software running for an extended time uses more and more memory. The software is not releasing its resources correctly! And so the machine cannot recoup memory.
It is possible that eventually the machine will crash, or the offending software will need restarted.
The two types of looping include the closed loop and the open loop.There is the count loop, the conditional loop and the unconditional loop.
Program that uses struct in c plus plus?
C++ of course uses classes (class) as opposed to structures (struct) for the purpose of keeping data members with an implicit 'private' access specifer as opposed to data members being 'public' by default (as with a struct.) Unless use of external C libs or routines are mandatory and wrapped in the appropriate C header(s), I don't know of any reason to use a struct anywhere in C++.
C-Program on reversing a digit?
int RevNum( int num )
{
const int base = 10;
int result = 0;
do
{
result *= base;
result += num % base;
} while( num /= base);
return( result );
}
Largest palindrome substring of a string?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector; /**
*
*/ /**
* @author omnipath
*
*/
public class Palindrome { /**
* @param args
*/
public static void main(String[] args) { // open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String string = null; // readLine() method try { string = br.readLine(); } catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); }
Palindrome palindromeCase = new Palindrome(string);
System.out.println("The longest palindrome is: " + palindromeCase.palindrome);
System.out.println("The length of the longest palindrome is: " + palindromeCase.palindrome.length());
System.out.println("Counter is: " + palindromeCase.PalindromeCounter);
} String originalString;
String palindrome;
Vector vectPalindromes;
int palindromeLength;
int PalindromeCounter; public Palindrome(String s) {
PalindromeCounter = 0;
this.palindrome = "";
this.palindromeLength = this.palindrome.length();
this.originalString = s;
this.calculateLongestPalindrome(s);
} public void calculateLongestPalindrome(String s) {
if (s.length() == 1) {
this.palindrome = this.originalString;
this.palindromeLength = this.palindrome.length();
} this.parseForPalindrome(this.originalString); } public void parseForPalindrome(String s) {
PalindromeCounter++;
if (s.length() -1; i--) {
sb.append(s.charAt(i));
}
return sb.toString();
}
}
I couldn't tell what answer your teacher expects to get for this question. Ask him/her personally.
What is the coding of a pogram in c to implement the builtin function of clrscr?
You could manipulate screen's video memory directly in order to achieve that. Video memory address in DOS text mode is allocated on segment 0xB800.
Look at the related links section, I've coded an example program for you that uses ClrScr() and ClrScrAsm() functions. Both featuring color support! ;)
Swap two number using pointer?
The only way to swap two values using call by value semantics is to pass pointer variables by value. A pointer is a variable that stores an address. Passing a pointer by value copies the address, the value of the pointer, not the pointer itself. By passing the addresses of the two values to be swapped, you are effectively passing those values by reference. Both C and C++ use pass by value semantics by default, however C++ also has a reference data type to support native pass by reference semantics. By contrast, Java uses pass by reference semantics by default.
In C, to swap two variables using pass by value:
void swap (int* p, int* q) {
int t = *p;
*p = *q;
*q = t;
}
In C++, to swap two variables using pass by reference:
void swap (int& p, int& q) {
std::swap (p, q);
}
Note that C++ is more efficient because std::swap uses move semantics; there is no temporary variable required to move variables. With copy semantics, a temporary is required. However, with primitive data types, there is a way to swap values without using a temporary, using a chain of exclusive-or assignments:
void swap (int* p, int* q) {
*p^=*q^=*p^=*q;
}