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

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

What is odd loop in 'C' program?

odd loop means at least the loop execute once.

What is a source code for memrise?

The Memrise website content, including program source code, is owned by Memrise Inc. Being proprietary intellectual property, the source code is not available within the public domain and therefore cannot be published here.

What is a block and node in drupal?

A node in block makes it possible to add nodes into block. A number of configurable blocks are generated which you can assign a region. Visibility setting of this block is automatically set to show on only the listed pages.

C program for the power operation?

WARNING: This program will not work for x power y where the resulting value is greater than 32767. Example: 10 power 10 will give you an incorrect value.

#include <stdio.h>

int main()

{

int num, power,i,ans;

printf("Enter number and power\t");

scanf("%d%d",&num,&power);

ans=num;

for(i=1;i<power;i++)

ans=ans*num;

printf("%d to the power %d = %d",num,power,ans);

return 0;

}

Difference between goto and continue statement in c language?

In continue statement,

we immediately continue next step through loop

In go to statement,

we go to in perfect label which we call.

A program prints vertically a numbers in c program?

It is too easy................

//Program to print numbers vertically

#include<stdio.h>

#include<conio.h>

void main()

{

int last_no;

int i;

clrscr();

i=0;

printf("Enter your last num.I will print 0 to that number");

scanf("%d",&last_no);

printf("\n");

while(i>last_no)

{

printf("%d\n",i);

i++;

}

getch();

}

//poo.papule

When was the Remington 32 short long RF made?

I can't give an exact date but the 22rf was (re) patent in 1859 and guns started appearing for it in 1860. Of course while very convenient everyone wanted larger calibers so they started immediately increasing the size and firearms for the 32 rf were available by around 1863. The rf design doesn't work well for larger calibers for several reasons due to the ignition of the powder and probably more significantly in order for the case to handle the pressures it would have to be thicker and of course the rf is fired by smashing that case rim and it would take stronger hammers/springs to do so. This is why the percussion handgun became the main stay for larger handguns until the development of the centerfire cartridge.

What are the advantages of hard disk drive?

1. Hard disk space is relatively cheap, as low as 13p per GB

2. Hard disks store data without the need for a constant electricity supply

3. Hard disks allow data to be stored in one place which is more convenient than using DVDs for example.

4 Hard drives have a read/write speed in comparison to optical media (cds) although very low in comparison to RAM