answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

What is the difference between interpreted and parsed?

Interpreted means - normally - the code is interpreted at run-time, while parsed (actually, it's "compiled") means the code is translated to a native object file at compile-time, and then executed. Compiled code is usually faster, also.

What is the difference between subscript and subscripted variable in c plus plus?

Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays.

The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants.

A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars.

Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).

How to solve Josephus problem using c?

Previous answer was in C++, please learn the difference.

/**********************************************************

*josephus.c: Solve the josephus problem for an arbitrary number of players *and an arbtitrary number of players missed each time.

*

*Author: XXX

*

*Input1:Number of players

*Input2:Number of players to miss each time

*Output:The lucky survivor

**********************************************************

#include <stdlib.h> /*For calloc, free and sizeof*/

#include <stdio.h> /*For printf, scanf*/

/*---Global structure to hold player details and a pointer to the next player---*/

struct player{

int player_num;

struct player *next;

};

int main (void) {

int i, j; /*Loop counters*/

int n; /*Number of players*/

int k; /*Number to skip each time*/

struct player *firstplayer; /*Hold firstplayer, so list can be circular linked*/

struct player *current_player; /*Hold current player*/

struct player *victim; /*Hold victim, for freeing*/

/*---Welcome statement---*/

printf("\njosephus.c: Program to solve the Josephus problem for an arbitrary number of "

"\n players and an arbitrary choice of count. The output will be the "

"\n number of the surviving player.\n\n");

/*---Request the number of players and assign to n---*/

printf("Please input the number of players.\n>>");

scanf("%d", &n) ;

/*---Request how many players to miss and assign to k---*/

printf("Please input the number of players you want to miss before execution.\n>>");

scanf("%d", &k);

/*---Alert the user, and exit the program, if they entered the wrong type of input---*/

if (n<=0 k<=0) {

printf("\a\n\nPlease enter positive integers only for the player and count!! "

"\nExiting...\n\n");

return 0;

}

/*---Set initial current player and firstplayer to be the same and assign space dynamically to hold them---*/

firstplayer=current_player=(struct player *)calloc(1, sizeof(struct player));

/*---Detect allocation failure---*/

if (current_player==NULL) {

printf("\a\nAllocation failure. Program terminates...\n\n");

exit(1);

}

current_player->player_num=1; /*Set the first/initial current players number to one*/

/*---Loop over n, assigning space for all the players and linking each successive one to

* the previous. Note: we do not count from 1, since already done above---*/

for (i=2; i<=n; ++i) {

current_player->next=(struct player *)calloc(1, sizeof(struct player));

/*---Detect allocation failure---*/

if (current_player->next==NULL) {

printf("\a\nAllocation failure. Program terminates...\n\n");

exit(1);

}

current_player=current_player->next; /*Current player now points to the next player*/

current_player->player_num=i; /*Define each player number*/

}

/*Finally link the final current player to the firstplayer, to make the list circular*/

current_player->next=firstplayer;

/*---Loop over n, counting up one every time a player dies---*/

for (i=1; i<n; ++i) {

/*Cycle through players until the one just before the unlucky one is reached*/

for (j=1; j<k; ++j) {

current_player=current_player->next;

}

/*Victim is the player just after the current player*/

victim=current_player->next;

/*Set the current player to point at the space just after where the victim was*/

current_player->next=current_player->next->next;

/*Set space now pointed to by victim free*/

free(victim);

}

/*Notify user of the game survivor*/

printf("\nThe lucky survivor is = %d\n\n", current_player->player_num);

/*---Set the final players space free---*/

free(current_player);

return 0;

}

C program for 2D convolution?

You can use ImageMagick library and use 'convolve' function.

Can we seal a 3 foot crack in a vent stack instead of replacing the entire stack and if so what materials would you use?

if it is above any water carrying capacity (area that has drain water flowing through it) and is truly just a vent stack it should be sealable using a clear silicone caulking.

Write c program to find median?

If you are using an array : sort using qsort() then take middle element.

Program to find n th fabonacci number?

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::tolower;

long factorial(const int& N);

int main()
{
int N = 0; //factorial of N
char command = 'n';
do
{
cout << "Enter a number to calculate factorial: ";
cin >> N;

cout << endl << "Factorial of " << N << " is: " << factorial(N) << endl;

cout << "Do you want to continue (y/n)?";
cin >> command;
cout << endl;
} while ('y' == tolower(command));

system("PAUSE");
return 0;
}

long factorial(const int& N)
{
if (N == 0)
{
return 1;
}
else
{
return (N * factorial(N - 1));
}
}

How are the strings passed to a function?

By reference. The name of the string is converted to a pointer (in C/C++) and given to the function as the address of the first element. (In Java, all objects are passed by reference, and there are no pointers.)

Why you use integer variables when the value of float and integer is same?

Integers are always guaranteed to be precise, provided you have sufficient bits to represent the number (plus the sign, if required). All logical and mathematical operations are extremely efficient when working with integers, even with division which simply truncates any fraction. If that's all the precision you need then you don't need to use a float. But if you need real numbers, then you must use a float.

Floating point numbers are never guaranteed to be accurate. Irrational numbers (such as pi and 1/3) are impossible to represent fully within a finite number of bits, thus there has to be a degree of precision. All floating point numbers are actually represented in computer memory using the binary equivalent of scientific notation, so even when dealing with small integer values, logic errors can creep in (such as 0.9 + 0.1 == 1.000000...01). Thus when working with floats you have to accommodate for the degree of precision.

Due to the increased complexity of floating point numbers, they are much less efficient than when working solely with integers. Thus if you can guarantee that a floating point number can be accurately represented as an integer (no fractions), then it makes more sense to use an integer. However, if you cannot make that guarantee then you must use a float.

Integer division can be problematic due to truncation, so it's often necessary to cast integers to floats to obtain a higher degree of precision, rounding the result as appropriate before casting back to an integer. Repeatedly converting back and forth can be costly, so it's sometimes better to just work with a float from the outset.

How do you use copy-paste in c and c plus plus program?

Copy/paste is facilitated by the operating system clipboard. This answer discusses the Windows operating system clipboard only. For other operating systems, consult the application programming interface (API) documentation related to that operating system.

Except for registering clipboard formats, individual windows perform most clipboard operations. A window procedure transfers information to or from the clipboard in response to the WM_COMMAND message.

The four conventional copy/paste commands are:

  • Cut : places a copy of the current selection on the clipboard and deletes the selection from the document. The previous clipboard content is destroyed.
  • Copy : command places a copy of the current selection on the clipboard. The previous clipboard content is destroyed.
  • Paste : replaces the current selection with the clipboard content. The clipboard content remains unchanged.
  • Delete : deletes the current selection from the document. The clipboard content remains unchanged.

These commands are conventionally provided via the window's context-sensitive Edit command menu, however they should also be mapped to the conventional keyboard accelerators: CTRL+X (cut), CTRL+C (copy), CTRL+V (paste) and DEL (delete).

[The Print Screen accelerator is usually mapped to the shell program (explorer.exe, by default). This accelerator is typically used to take a snapshot of the current desktop (ALT+Print Screen takes a snapshot of the active window). The snapshot (a 1:1 bitmap image) is copied to the clipboard, replacing the current clipboard content.]

The clipboard owner is the window associated with the current information on the clipboard. A window becomes the owner when it places information on the clipboard -- specifically, when it invokes the EmptyClipboard function. The window remains the owner until the window is closed or another window empties the clipboard.

The EmptyClipboard function posts a WM_DESTROYCLIPBOARD message to the current clipboard owner and assigns ownership to the current window. Upon receiving a WM_DESTROYCLIPBOARD message, a clipboard owner must release all resources associated with the information it owns.

Once the clipboard is emptied, the new owner may place new information upon the clipboard. Information can be stored in one or more supported formats, including user-defined formats. The standard formats are:

CONSTANT (value): Description

CF_TEXT (1): Text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. Use this format for ANSI text.

CF_BITMAP (2): A handle to a bitmap (HBITMAP).

CF_METAFILEPICT (3): Handle to a metafile picture format as defined by the METAFILEPICT structure. When passing a CF_METAFILEPICT handle by means of DDE, the application responsible for deleting hMem should also free the metafile referred to by the CF_METAFILEPICT handle.

CF_SYLK (4): Microsoft Symbolic Link (SYLK) format.

CF_DIF (5): Software Arts' Data Interchange Format.

CF_TIFF (6): Tagged-image file format.

CF_OEMTEXT (7): Text format containing characters in the OEM character set. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data.

CF_DIB (8): A memory object containing a BITMAPINFO structure followed by the bitmap bits.

CF_PALETTE (9): Handle to a colour palette. Whenever an application places data in the clipboard that depends on or assumes a colour palette, it should place the palette on the clipboard as well. If the clipboard contains data in the CF_PALETTE(logical colour palette) format, the application should use the SelectPalette and RealizePalette functions to realise (compare) any other data in the clipboard against that logical palette. When displaying clipboard data, the clipboard always uses as its current palette any object on the clipboard that is in the CF_PALETTE format.

CF_PENDATA (10): Data for the pen extensions to the Microsoft Windows for Pen Computing.

CF_RIFF (11): Represents audio data more complex than can be represented in a CF_WAVE standard wave format.

CF_WAVE (12): Represents audio data in one of the standard wave formats, such as 11 kHz or 22 kHz

PCM.

CF_ENHMETAFILE (14): A handle to an enhanced metafile (HENHMETAFILE).

CF_UNICODETEXT (13): Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data.

CF_HDROP (15): A handle to type HDROP that identifies a list of files. An application can retrieve information about the files by passing the handle to the DragQueryFilefunction.

CF_LOCALE (16): The data is a handle to the locale identifier associated with text in the clipboard. When you close the clipboard, if it contains CF_TEXT data but no CF_LOCALE data, the system automatically sets the CF_LOCALE format to the current input language. You can use the CF_LOCALE format to associate a different locale with the clipboard text. An application that pastes text from the clipboard can retrieve this format to determine which character set was used to generate the text. Note that the clipboard does not support plain text in multiple character sets. To achieve this, use a formatted text data type such as RTF instead. The system uses the code page associated with CF_LOCALE to implicitly convert from CF_TEXT to CF_UNICODETEXT. Therefore, the correct code page table is used for the conversion.

CF_DIBV5 (17): A memory object containing a BITMAPV5HEADER structure followed by the bitmap colour space information and the bitmap bits.

CF_OWNERDISPLAY (0x0080): Owner-display format. The clipboard owner must display and update the clipboard viewer window, and receive the WM_ASKCBFORMATNAME, WM_HSCROLLCLIPBOARD, WM_PAINTCLIPBOARD, WM_SIZECLIPBOARD, and WM_VSCROLLCLIPBOARD messages. The hMem parameter must be NULL.

CF_DSPTEXT (0x0081): Text display format associated with a private format. The hMem parameter must be a handle to data that can be displayed in text format in lieu of the privately formatted data.

CF_DSPBITMAP (0x0082): Bitmap display format associated with a private format. The hMem parameter must be a handle to data that can be displayed in bitmap format in lieu of the privately formatted data.

CF_DSPMETAFILEPICT (0x0083): Metafile-picture display format associated with a private format. The hMem parameter must be a handle to data that can be displayed in metafile-picture format in lieu of the privately formatted data.

CF_DSPENHMETAFILE (0x008E): Enhanced metafile display format associated with a private format. The hMem parameter must be a handle to data that can be displayed in enhanced metafile format in lieu of the privately formatted data.

CF_PRIVATEFIRST (0x0200): Start of a range of integer values for private clipboard formats. The range ends with CF_PRIVATELAST. Handles associated with private clipboard formats are not freed automatically; the clipboard owner must free such handles, typically in response to the WM_DESTROYCLIPBOARD message.

CF_PRIVATELAST (0x02FF): See CF_PRIVATEFIRST.

CF_GDIOBJFIRST (0x0300): Start of a range of integer values for application-defined GDI object clipboard formats. The end of the range is CF_GDIOBJLAST. Handles associated with clipboard formats in this range are not automatically deleted using the GlobalFree function when the clipboard is emptied. Also, when using values in this range, the hMem parameter is not a handle to a GDI object, but is a handle allocated by the GlobalAlloc function with the GMEM_MOVEABLE flag.

CF_GDIOBJLAST (0x03FF): See CF_GDIOBJFIRST.

For more information, consult the Windows Dev Centre. Search for "Clipboard".

How many 8 bit characters does the ASCII standard define?

128 (0-127), 95 printable, 33 control (for 7 bit ascii that is a through back to teletypes.)

ISO 8859-1 has 256 characters.

From 128 up to 255 we find extra symbols for other languages and regions. Ascci 128 = € for instance and 255 = ÿ.

Of course there are many 8-bit standars, windows-1250, for an example.

How do you write area?

You have already done it: "area".

for a rectangle: length x width = area 2

(always put the little 2 the end of the equation, or else it isn't counted as the area)

What is a function module?

Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.

What is control statement give answer with its types?

A control statement is any statement that affects the flow of execution.

The simplest control statement is the if statement:

if (x!=0) x++;

When execution reaches this statement, the control expression, x!=0, is evaluated. If it evaluates false (in which case x is zero) execution moves onto the next statement. However, if it evaluates true (in which case x is non-zero), the remainder of the statement is executed, incrementing x before moving onto the next statement.

The controlled statement may also be a compound statement:

if (x!=0) { x++;

x*=2;

}

As before, x!=0 is evaluated. If false, execution passes to the statement following the closing brace. If true, the compound statement is executed, first incrementing x and then doubling x. Execution then falls through to the next statement after the closing brace.

Sometimes we may wish to execute a different statement when the control expression evaluates false. In this case we use an if-else statement:

if (x==0)

x++;

else

x*=2;

Here we evaluate x==0. If true, we increment x but if false, we double x. Only one or the other statement executes, never both. Whichever is executed, execution falls through to the next statement. Again, the controlled statement may be a compound statement.

The else clause of an if statement can also be another if statement, known as a nested if:

if (x==0)

x++;

else if (x==1)

x*=2;

else if (x==2)

x*=3;

else

x*=4;

Nested ifs are evaluated in the order they appear. However, when the control expressions contain a common sub-expression (here, x), a switch is usually a better choice:

switch (x) {

case 0: x++; break

case 1: x*=2; break;

case 2: x*=3; break;

default: x*=4;

}

Here, x is evaluated and execution passes to the corresponding case label. Execution continues from that point unless a break statement is encountered, at which point execution passes to the statement that follows the closing brace of the switch statement.

Note that a break statement is also a control statement. We can also use return (another control statement) to break out of a switch.

Loops are also control statements:

for (int x=0; x<10; ++x) printf ("%d ", x);

Here we assign 0 to x, then evaluate the control expression, x<10. This is true (zero is less than ten), so the printf() function executes. We then execute the action expression, ++x, before evaluating the control expression again. this time x is 1 and 1<10 is true, so the printf() function executes again. We continue incrementing x and evaluating x<10. So long as x<10 remains true, the printf() function is invoked. After 10 iterations, x will be 10, at which point x<10 evaluates false, so execution now passes to the next statement.

We can implement the same loop using a while statement:

int x = -1;

while (++x<10) printf ("%d ", x);

Here, the initialiser is outside the loop, thus x is now in scope when the loop ends. We can do the same with for loops, provided the control variable is in scope before we enter the loop. Note that the action (++x) is now a sub-expression of the control expression. It is a matter of taste whether this code is more readable than a for loop, however for loops are arguably better suited to counted loops.

While loops are better suited to "infinite" loops such as message queues:

Message msg;

while (true) { // execute "for ever"

idle();

msg = parse_message ();

if (msg==EXIT) break;

process_message (msg);

}

This is a stylised (simplified) message queue. Here, we execute the loop continuously. We start by entering idle mode which returns when there is a message on the queue. We then parse the message. If the msg is EXIT, we break out of the loop. Otherwise we dispatch the message and repeat from the beginning. Note that "infinite" loops are never truly infinite: you must provide some means of breaking out of the loop at some point. Here we used the EXIT message.

Another control statement is the continue statement. This only appears in loops and can be used to skip over any remaining statements in the loop without breaking out of the loop.

int x = 0;

do {

++x;

if (x==5) continue;

printf ("%d ", x);

} while (x<10);

Here we print the value of x until x is 10. However, when x is 5, we do not print x, we jump to the control expression where x<10 is re-evaluated.

Note the final example shows a do-while loop and is used whenever we wish the body of the loop to execute at least once, regardless of the control expression which is evaluated at the end of each iteration, rather than at the beginning. However, the type of loop does not matter; the continue statement always skips the remainder of the loop but does not exit the loop.

A goto statement is also a control statement. However, use goto sparingly and only when required. Code that jumps about too much is difficult to read; code that is hard to read is also hard to maintain. The same can also be said of break, continue and return statements.

Function calls are also considered control statements because they (usually) interrupt the flow of execution via the call and return mechanism. The exceptions are inline expanded functions which give you all the advantages of a function (i.e., localisation of common code) without the expense of a function call.

What is an array for 2 times 3?

An array of 2 times 3 is a one-dimensional array of 2 elements each of which is a one-dimensional array of 3 elements. In other words, it is an array of arrays, also known as a two-dimensional array. We can imagine a two dimensional array as being a table with rows and columns. A 2 times 3 array has 2 rows and 3 columns. Each row is itself an array of 3 elements. However, we can also say that each column is an array of 2 elements.

What is the c program to find fibnocci series?

#include<stdio.h>

#include<conio.h>

void main()

{

}

Can you deallocate memory of a null pointer?

In the case of C, execution halts with a segmentation fault because the literal address of NULL is never allocated to a running program.

Why C language is called mid level language justify with an example?

C language support bit-level manipulation that are normally done in assembly or machine level language. C reduce the gap between high level and low level

language. So, it's called as middle level language.

Write a c programme with lucas series?

//Lucas series - 2,1,3,4,7,11,18

#include <stdio.h>

#define PRINTMAX 50

void lucas(int first, int second) //Prints 52 numbers

{

int count=1,total;

printf("%d\t%d\t",first,second);

while (count < PRINTMAX)

{

total = second + first;

printf("%d\t",total);

first = second;

second = total;

count++;

}

}

int main(void)

{

lucas(2,1);

return 0;

}

Conversion of expression in binary tree in data structure?

1 Mayuresh Pardeshi (pardeshimayuresh@gmail.com) /*Binary Tree Expression Solver 2 * By James Brannan, 2005. 3 * irregularexpression@gmail.com 4 * You may copy and redistribute 5 * this code free of charge as you 6 * see fit. 7 */ 8 9 using System; 10 using System.Collections.Generic; 11 using System.Text; 12 13 14 namespace Tree 15 { 16 // Node Class: Base for binary tree, holds data for left and right nodes. 17 class Node 18 { 19 // Stack used to solve for a given tree. 20private Stack stack = new Stack(); 21 22 // Solves a tree 23 public int Solve() 24 { 25 /* This method uses a stack to solve the expression. The postfix 26 * notation is tokenized and systematically added to the stack. 27 * When the stack encounters an operation, it is executed and 28 * modifies the contents on stack. The final item left on the 29 * stack (given the expression was valid) is the answer. 30 */ 31 string a , b; // Temporary placeholders for popped values 32 string[] tokens = Postfix().Split(' '); // Tokenize the postfix output 33 foreach (string e in tokens) 34 { 35 switch (e) 36 { 37 /* For operation cases, the last two items added to the stack are 38 * removed and acted upon. For any other case, the value is pushed 39 * onto the stack. 40 */ 41 case "+": 42 b = stack.Pop(); 43 a = stack.Pop(); 44 stack.Push(Convert.ToString(Convert.ToInt16(a) + Convert.ToInt16(b))); 45 break; 46 case "-": 47 b = stack.Pop(); 48 a = stack.Pop(); 49 stack.Push(Convert.ToString(Convert.ToInt16(a) - Convert.ToInt16(b))); 50 break; 51 case "/": 52 b = stack.Pop(); 53 a = stack.Pop(); 54 stack.Push(Convert.ToString(Convert.ToInt16(a) / Convert.ToInt16(b))); 55 break; 56 case "*": 57 b = stack.Pop(); 58 a = stack.Pop(); 59 stack.Push(Convert.ToString(Convert.ToInt16(a) * Convert.ToInt16(b))); 60 break; 61 case "%": 62 b = stack.Pop(); 63 a = stack.Pop(); 64 stack.Push(Convert.ToString(Convert.ToInt16(a) % Convert.ToInt16(b))); 65 break; 66 default: 67 stack.Push(e); 68 break; 69 } 70 } 71 // Value left over is the result of the expression 72 return Convert.ToInt16(stack.Pop()); 73 } 74 75 // Returns the prefix notation for the expression 76 public string Prefix() 77 { 78 /* Function recurses through the left then right 79 * nodes after its value. 80 */ 81 string res = this.Value + " "; 82 if (this.left != null) // If node is not a leaf, then recurse 83 { 84 res += this.left.Prefix(); 85 res += this.right.Prefix(); 86 } 87 return res; 88 } 89 90 // Returns the postfix notation for the expression 91 public string Postfix() 92 { 93 /*Function recurses through the left then right, 94 * bottom-up. All leafs are returned before their 95 * parent operators. 96 */ 97 string res = ""; 98 if (this.left != null) //If node is not a leaf, then recurse 99 { 100 res += this.left.Postfix() + " "; 101 res += this.right.Postfix() + " "; 102 } 103 res += this.Value; 104 return res; 105 } 106 107 // Returns the (fully parenthesized) infix notation for the expression 108 public string Infix() 109 { 110 /*Function recurses through left, then returns 111 * value, and recurses right. Each expression is 112 * nested in parentheses. 113 */ 114 string res = ""; 115 if (this.left != null) 116 { 117 res = res + "(" + left.Infix() + " " + Value + " " + right.Infix() + ")"; 118 } 119 else 120 { 121 res += Value; 122 } 123 return res; 124 } 125 126 // Constructor for subnodes 127 public Node(char op, Node l, Node r) 128 { 129 left = l; 130 right = r; 131 Value = op.ToString(); 132 } 133 // Constructor for leaf nodes 134 public Node(string value) 135 { 136 //Leaf nodes have no left or right subnodes 137 left = null; 138 right = null; 139 Value = value; 140 } 141 142 //Node connected on the left 143 private Node left; 144 // Node connected on the right 145 private Node right; 146 // Value (operator or term) 147 private string Value; 148 } 149 150 // Sample program: 151class Program 152 { 153 /* The code below demonstrates the use of the Node class. The expression being 154 * tested is graphed as shown below. (Make sure you're using a monospace font) 155 * (((1-2)-3) + (4*(5+6))) 156 * + 157 * / \ 158 * - * 159 * / \ / \ 160 * - 3 4 + 161 * / \ / \ 162 * 1 2 5 6 163 */ 164 165 static void Main(string[] args) 166 { 167 Node root = new Node('+', new Node('-', new Node('-', new Node("1"), new Node("2")), new Node("3")), 168 new Node('*', new Node("4"), new Node('+', new Node("5"), new Node("6")))); 169 Console.WriteLine("Prefix notation: \t" + root.Prefix()); 170 Console.WriteLine("Postfix notation: \t" + root.Postfix()); 171 Console.WriteLine("Infix notation: \t" + root.Infix()); 172 Console.WriteLine("Solution for tree is:\t" + root.Solve()); 173 Console.ReadKey(true); 174 } 175 } 176 }

Difference between class and structure in csharp?

I'm not sure about csharp, but in OO a class has a state and behaviour whereas structure has only state.

The state of a class is the data members, or attributes of a class. Behaviour of a class is the function members, or the methods of a class. Ie, a class has attributes and functions, but a struct has only attributes.

Historically, classes derived from structures. At one point someone thought of adding behaviour or functionality to structures and the resulting type was called a class.

I'll give you an example.

struct Student {
//state
int YearInCollege;
};

This structure has only data members that can be manipulated in the program. Eg:

Student You;
You.YearInCollege=1; //change state
...
int a=You.YearInCollege; //read state

As you can see, we can read and write the members of a structure as we wish.

Now, let's give the structure a bit of functionality.

class Student {
//behaviour
int WhatsMyYearInCollege(void);
void ChangeMyYearInCollege(int);

//state
int YearInCollege;
};

as you can see, now besides the state we also have functionality to change the state of the class. Now, we'll change the state of the class only through its own member functions, also called mutator functions. Eg:

Student You;

You.ChangeMyYearInCollege(2); //change state through class' own function
...
int a=You.WhatsMyYearInCollege(); //read state through class' own function