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 convert 50 from decimal to binary?

Repeatedly divide the decimal value by 2 and take the remainder (which can only be 0 or 1) until the decimal value is 0. The first remainder is the low-order bit, thus we work through the bits in increasing order of magnitude.

For example, decimal value 50:

50 / 2 = 25 r 0

25 / 2 = 12 r 1

12 / 2 = 6 r 0

6 / 2 = 3 r 0

3 / 2 = 1 r 1

1 / 2 = 0 r 1

Thus 50 decimal is 110010 in binary.

How do you Write a program in c language to calculate the sum of two integers?

#include

#include

#include

void main()

{

char a;

int firstInt, secondInt, sum;

cout << "Enter two integers/n:";

cin >> firstInt >> secondInt;

sum = firstInt + secondInt;

cout << "The result is: " << sum;

getch(a);

}

What are storage classes in c?

There are four types of storage classes in c. It defines the scope and lifetime of a variable or function.

1. auto - This is the default storage class inside a function. Auto can only be used with in functions. i.e. only for local variables, not for globals.

2. register - The variables declared using the register storage class may stored in CPU registers instead of RAM. Since it doesn't have a memory location, the '&' operator for getting the address of the variable cannot be applied (in C). This storage class cannot be used for global scope data.

3. static - In case of local variable, it is initialized at compile time and retains its value between the calls. By default the static variables will be initialized to zero, in case of pointer variable initialized to NULL.

4. extern - Refers to a public variable defined somewhere else (often in a different source file.)

CPU's operate in 3 modes 16 bit 32 bit and 64 bit Respectively the 3 modes are also called?

real mode, protected mode and long mode real mode, protected mode and long mode

Or: 16-bit modes (real, protected or virtual), 32-bit mode (protected), 64-bit modes

What is the similarities of High Level Language and machine language?

Nothing. Example:

machine code: 05 CA DE 12 15 47 A8

High level language: PRINT "Hello, World"

How do you search a character in a inputted string?

#include <iostream>

#include <string>

using std::string;

using std::cin;

using std::cout;

using std::endl;

using std::getline;

int main()

{

string myString = "";

cout << "Enter a string: ";

getline(cin, myString);

char mySymbol = 'a';

cout << "Enter a symbol to search for: ";

mySymbol = getchar();

bool symbolFound = false;

for (int index = 0; index < myString.length(); index++)

{

if (mySymbol false)

{

cout << "The symbol " << mySymbol << " was not found!";

}

cin.get();

cin.get();

return 0;

}

How newline character formed?

The newline or line-feed character is denoted by ASCII code 0x0A (decimal 10). In C, we use the escape-sequence '\n' to denote a new line. In some cases, particularly where the output is directed to a line printer, a newline is immediately preceded by a carriage return character, 0x0D (13 decimal), which is denoted by the escape sequence '\r' in C. Thus you will often encounter the "\r\n" escape sequence at the end of each line of ASCII text.

What is 58 c in c?

Conversion from Celsius to Fahrenheit is done in three steps:

1. Multiply value in degrees Celsius by 9.

2. Divide result of step 1 by 5.

3. Add 32 to result of step 2.

Conversion formula: [°F] = [°C] * 9 / 5 + 32 = 58 * 9 / 5 + 32 = 136.4 °F

How do you print array variable without using array subscripts?

Well the most prolific answer to this query would be the use of pointers.Use a pointer and allocate it to the array of interest and start printing.

How do you initialize more than one variable in a for loop?

example with two variables (j and d):

for (i=0; i<10; ++i)

{

int j=1;

double d=8.0;

... more statements ...

}

What is the absolute machine code?

The very lowest possible level at which you can program a computer is in its own native machine code, consisting of strings of 1's and 0's and stored as binary numbers. The main problems with using machine code directly are that it is very easy to make a mistake, and very hard to find it once you realize the mistake has been made.

What is the difference between functions and variables?

Variables define a certain value, such as an integer, string, boolean value, etc. Functions are defined to run a certain task, and may or may not return a value. You can have a function that calculates the sum of two numbers and returns the sum once calculated.

How you can use while loop in place of select case?

While is NOT a replacement for SWITCH -- CASE

However , still if this is the requirement then , you can do this :

While (1)

{

if (case1 ) {}

if (case2 ) {}

:

:

:

if (case n ) {}

if (case default ) {}

} //end of while loop

What is the function that eliminates the need to place the function definition before all calls to the function?

A forward declaration. In all statically typed languages (such as C++), all types must be declared before they can be used. A function is a type (the return value defines its type), but the compiler only needs to know how the function is called, not how it is implemented, so the function definition does not need to be visible to the compiler before the function can be called. The definition can actually be placed in another translation unit entirely.

Note that a function definition is also a function declaration.

Forward declarations make it possible for two functions to be dependent upon each other.

A function declaration includes the return type, the name of the function and its argument types. The formal names of a function's arguments are not required in it's declaration, they are only required in its definition. A function's signature is the same as its declaration but excludes the return type. All calls to a function must match its signature. If the return type is used, it must be assigned to a type that is covariant with the declared type.

Function declarations are typically placed in header files. By including the header in every translation unit that uses the function, we ensure the function's declaration is consistent across all translation units. If the function is defined in the same header it is declared, then it must also be declared inline. Multiple definitions of the same function are permitted provided they are token-for-token identical, thereby adhering to the one definition rule (ODR).

How do i write a program in c langua ge for the implementation of binary search with output?

There are various ways to implement a binary search, but the simplest makes use of a sorted array. It must be sorted because we need to know where values are in relation to one another. That is, if we know that element X has the value Y, then all values less than Y must be in the first half of the array, and all values greater than Y must be in the second half of the array.

We begin by looking at the middle element of the array. If there is no middle element (the array is empty) then the value does not exist. But if the middle value holds the value we are looking for, we are done. Otherwise we compare values to decide which half of the array can be eliminated. We then repeat the process with the remaining half of the array.