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 purpose do braces serve in C programming?

grouping statements. eg:

if (i==2) printf ("i==");

printf ("2");

and

if (i==2) {

printf ("i==");

printf ("2");

}

do different things, if i<>2

What steps are required form an algorithm to convert a binary number to it's decimal equivalent?

Let's look at an example. If you want to convert the number 100112 to decimal you can split up the number so each digit has an index associated to it:

4 3 2 1 0

1 0 0 1 1

We can then find the decimal value:

24 * 1 + 23 * 0 + 22 * 0 + 21 * 1 + 20 * 1 =

16 * 1 + 8 * 0 + 4 * 0 + 2 * 1 + 1 * 1 = 16 + 0 + 0 + 2 + 1 = 19

So what we need to do is to multiply each of the binary digits by the value of two raised to the index of the digit. This will give you the conversion from any binary number to a decimal number.

What are the differences between thread and function in C plus plus?

As people do computer has head to think and hands to work. Under the control of it's head(CPU), you can consider threads as its hands. A computer has more than one hand, every hand would do one thing independently but have to wait its order. Function, as it demonstrate by the name, means what task a software can conduct.

How do you reverse the order of the elements in the array?

Start by pointing to each end of the array. Work your way towards the middle of the array, swapping elements as you go. When the pointers meet or pass each other, the array is completely reversed.

Program to shut down a PC in c?

Well C language is a programming language it is used for designing programs. So you must be confused i can tell you how to shut your computer down using the command prompt though

*Step one open start and click run type cmd and press enter

*step two once the command prompt has opened type shutdown -i and press enter a dialogue box will appear

*Step three at the top of the box there is a button that says ADD click that and type your computers name if if you do not know your computers name opn the control panel then open system and choose the tab on the top that says computer name your computers full name will be located here

*Step four copy and paste your computers name into the box that popped up when you clicked add click ok now your computers name has been added to the list now from the drop down menu select what you want your computer to do restart shut down etc.

type a comment and select ok your computer should shutdown

Explain the structure of c program with an suitable example?

Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main()

{

Declaration part Executable part (statements)

} /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) .

.

. (return type) (function name n) (arguments...) Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main()

{

Declaration part Executable part (statements)

} /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) .

.

. (return type) (function name n) (arguments...)

What is the meaning of percent s in C programming?

%d is used as a format mask to represent an integer.

Any of the "formatted" io functions can use this: printf, fprintf, scanf, etc.

Example:
int i = 0;
printf("%d", i); // prints the value of i
This is a format specifier which is used to identify that the given input is an integer or not
In C: c%d means the remainder dividing c with d

in printf/scanf format string: %d means an integer data
For extracting or inserting data which is signed integer in decimal format

Types of interrupt?

There are a great many ways in which you could interrupt a person while they talk. You could talk over them.

Is an array that is in sorted order a min-heap?

Yes, an array that is in sorted order is considered a min-heap because the smallest item in the array is the root. Also, the rest of the items in the array will gradually get bigger from the root until the end of the array.

In programming what values do not change?

const type, for instance (const double = 1.1; this you cannot change during run)

How are string variables stored?

Typically as null-terminated character arrays. However, some languages use the first element of the array to store the length of the string rather than a null-terminator to mark the end of the string.

Define documentation section of a c program?

The different sections of a program are: 1. Heap 2. Stack 3.Data segments 4. Read only area 5. Code You can also look into google for more information http://en.wikipedia.org/wiki/Data_segment

How can you find factorial of an array?

#include
#include
void main()
{
int fact(int n);
clrscr();
printf("%d",fact(5));
getch();
}
int fact(int n)
{
int fact=1;
while(n>=1)
{
fact=fact*n;
n--;
}
return fact;
}

What is the array of 9?

it's to do with the structure of cilia and microtubules

How does virtual function support run time polymorphism?

Virtual functions are used to suport runtime polymorphism.In C++,if we have inheritance and we have overridden functions in the inherited classes,we can declare a base class pointer and make it to point to the objects of derived classes.When we give a keyword virtual to the base class functions,the compiler will no do static binding,so during runtime ,the base class pointer can be used to call the functions of the derived classes.Thus virtual functions support dynamic polymorphism.

How constructor called?

You cannot invoke a constructor explicitly. It will get invoked implicitly when you call the new keyword on the class to create an object of the class.

Ex:

private ClassExample obj = new ClassExample();

here this new keyword usage on the ClassExample class will invoke the constructor of this class and create an object of that class.

Advantages of computer animation?

The only disadvantage I can think of is that computer graphics requires a lot of processing time.

C program to design a car?

#include<stdio.h>

#include<graphics.h>

#include<math.h>

#include<conio.h>

#include<dos.h>

#include<alloc.h>

#include<stdlib.h>

#define RAD 3.141592/180

class fig

{

private:

int x1,x2,y1,y2,xinc,yinc;

public:

void car()

{ xinc=10;yinc=10;

x1=y1=10;

x2=x1+90;y2=y1+35;

int poly[]={x1+5,y1+10,x1+15,y1+10,x1+20,y1,x1+50,y1,x1+60,y1+10,x1+90,y1+17,x1+90,y1+20,x1+5,y1+20,x1+5,y1+10};

setfillstyle(SOLID_FILL,LIGHTGRAY);

setlinestyle(SOLID_LINE,1,2);

setcolor(4);

drawpoly(9,poly);

line(x1+15,y1+10,x1+60,y1+10);

line(x1+20,y1+10,x1+20,y1);

line(x1+35,y1+10,x1+35,y1);

line(x1+50,y1+10,x1+50,y1);

floodfill(x1+18,y1+8,4);

floodfill(x1+28,y1+8,4);

floodfill(x1+36,y1+8,4);

floodfill(x1+52,y1+8,4);

setfillstyle(SOLID_FILL,4);

floodfill(x1+18,y1+12,4);

setfillstyle(SOLID_FILL,BLUE);

bar(x1+5,y1+20,x1+90,y1+25);

setcolor(DARKGRAY);

circle(x1+20,y1+25,8);

circle(x1+20,y1+25,6);

setfillstyle(1,8);

floodfill(x1+21,y1+25,8);

circle(x1+70,y1+25,8);

circle(x1+70,y1+25,6);

floodfill(x1+71,y1+25,8);

int size=imagesize(x1,y1,x2,y2);

void far *buf=farmalloc(size);

getimage(x1,y1,x2,y2,buf);

while(!kbhit())

{ putimage(x1,y1,buf,XOR_PUT);

x1+=xinc;x2+=xinc;

if(x2<(getmaxx()-10))

putimage(x1,y1,buf,COPY_PUT);

else

{ cleardevice();

x1=10;x2=x1+90;

y1+=yinc;y2+=yinc;

if(y2<(getmaxy()-10))

{ putimage(x1,y1,buf,COPY_PUT);

}

else {y1=10;y2=y1+35;}

}

delay(200);

}

farfree(buf);

getch();

}

}

}

}

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"d:\\cplus");

fig f;

f.car();

cleardevice();

closegraph();

}

Write a program to concatenate two strings in C plus plus?

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::getline;

int main()
{
string firstLine = "";
cout << endl << "Enter first line: ";
getline(cin, firstLine);

string secondLine = "";
cout << endl << "Enter second line: ";
getline(cin, secondLine);

cout << endl << "Two strings concatenated together: " << firstLine + secondLine << endl;

system("PAUSE");
return 0;
}

How would you write the number 37 in binary?

100101 1 times 2^0 = 1 PLUS 0 times 2^1 = 0 PLUS 1 times 2^2 = 4 PLUS 0 times 2^3 = 0 PLUS 0 times 2^4 = 0 PLUS 1 times 2^5 = 32 EQUALS 37

How do you declare gotoxy?

You don't declare library functions. Simply include conio.h. For details use the built-in help.

How do you write a c program for hashing?

- Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms. As a simple example of the using of hashing in databases, a group of people could be arranged in a database like this: Abernathy, Sara Epperdingle, Roscoe Moore, Wilfred Smith, David (and many more sorted into alphabetical order) Each of these names would be the key in the database for that person's data. A database search mechanism would first have to start looking character-by-character across the name for matches until it found the match (or ruled the other entries out). But if each of the names were hashed, it might be possible (depending on the number of names in the database) to generate a unique four-digit key for each name. For example: 7864 Abernathy, Sara 9802 Epperdingle, Roscoe 1990 Moore, Wilfred 8822 Smith, David (and so forth) A search for any name would first consist of computing the hash value (using the same hash function used to store the item) and then comparing for a match using that value. It would, in general, be much faster to find a match across four digits, each having only 10 possibilities, than across an unpredictable value length where each character had 26 possibilities. The hashing algorithm is called the hash function (and probably the term is derived from the idea that the resulting hash value can be thought of as a "mixed up" version of the represented value). In addition to faster data retrieval, hashing is also used to encrypt and decrypt digital signatures (used to authenticate message senders and receivers). The digital signature is transformed with the hash function and then both the hashed value (known as a message-digest) and the signature are sent in separate transmissions to the receiver. Using the same hash function as the sender, the receiver derives a message-digest from the signature and compares it with the message-digest it also received. They should be the same. The hash function is used to index the original value or key and then used later each time the data associated with the value or key is to be retrieved. Thus, hashing is always a one-way operation. There's no need to "reverse engineer" the hash function by analyzing the hashed values. In fact, the ideal hash function can't be derived by such analysis. A good hash function also should not produce the same hash value from two different inputs. If it does, this is known as a collision. A hash function that offers an extremely low risk of collision may be considered acceptable. Here are some relatively simple hash functions that have been used: * The division-remainder method: The size of the number of items in the table is estimated. That number is then used as a divisor into each original value or key to extract a quotient and a remainder. The remainder is the hashed value. (Since this method is liable to produce a number of collisions, any search mechanism would have to be able to recognize a collision and offer an alternate search mechanism.) * Folding: This method divides the original value (digits in this case) into several parts, adds the parts together, and then uses the last four digits (or some other arbitrary number of digits that will work ) as the hashed value or key. * Radix transformation: Where the value or key is digital, the number base (or radix) can be changed resulting in a different sequence of digits. (For example, a decimal numbered key could be transformed into a hexadecimal numbered key.) High-order digits could be discarded to fit a hash value of uniform length. * Digit rearrangement: This is simply taking part of the original value or key such as digits in positions 3 through 6, reversing their order, and then using that sequence of digits as the hash value or key. A hash function that works well for database storage and retrieval might not work as for cryptographic or error-checking purposes. There are several well-known hash functions used in cryptography. These include the message-digest hash functions MD2, MD4, and MD5, used for hashing digital signatures into a shorter value called a message-digest, and the Secure Hash Algorithm (SHA), a standard algorithm, that makes a larger (60-bit) message digest and is similar to MD4.