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

Can you use conditional operator in cout statement?

Yes, but 'cout' is not a statement! Examples for statements: null-statement, block, expression, if-else, while, do-while, for, continue, switch, break, return.

Where is pointer located?

A pointer is a variable that stores the memory address of another variable. In programming, pointers are typically located in the stack if they are local variables within a function, or in the heap if they are dynamically allocated. The actual data that the pointer points to can reside in either memory area, depending on how it was allocated.

What is the term for a space memory used to store information for later use?

A space used by memory to store information for later use is called the cache (pronounced like cash).

What is the importance of union in a c program?

Importance of union in 'C':

unions are the concept borrowed from structures in structures we allow different datatypes in which each datatype is allocated a separate memory location .But in unions same as structures we use different data types but all the datatypes will be allocated to a single memory location and only one datatype with maximum size will be used for allocation of all the data types used in a union program.Sample code for union is as follows:

union item

{

int m;

float c;

char x;

}code;

In the above program we used three kinds of datatypes here integer size is 4 so the other data types will be shared in the same location of size 4.then the memory will not be wasted and all the memory will be utilized perfectly.

Why a function is not defined in to another function?

A function is not deigned in to another function. It is because that would lead to dependency injection.

When you pass an array element to a method the method receives?

Yes, you can use array-elements as parameters. Do you have any problem with that?

What are the values of abc and d if a is a is factor of b c is the second multiple of b and the fourth multiple of a d is a prime number between 10 and 20 and all numbers are different and add to 41?

1. a is a factor of b.

2. c = 2b = 4a, thus b = 2a and c = 4a.

3. d is prime between 10 & 20.

4. a + b + c + d = 41.

Therefore: a + 2a + 4a + d = 41

7a + d = 41

d = 41 - 7a

The only integer value for awhich results in d being a prime between 10 and 20 is where a = 4.

If a = 4 then

b = 2a = 4 * 2 = 8

c = 4a = 4 * 4 = 16

d = 41 - (7*4) = 41 - 28 = 13

The numbers are thus 4,8,16 and 13.

Are arrays in C created on the stack or the heap?

That depends on where you define them. Arrays defined inside functions are declared on the stack (like other variables defined in functions). Arrays defined outside of any function, or using the static keyword inside a function are allocated in the static data area of the program.

Other arrays may be allocated using malloc() (or "new" in C++); these are allocated on the heap.

Why you use Loops?

Loops are used to repeat the execution of the same set of instructions again and again in a program.

What is the sum of a two digit number less the sum of its digits?

There exist no numbers which are less than the sum of their digits.

This is obvious for single digit numbers, since each number would be exactly equal to the sum of its digits.

For multi-digit numbers, this still holds true. Let's take a two digit number in the form: ab. Where a and b represent the digits of this number.

The sum of the digits of ab = a + b.

The number ab = a*10 + b.

It should now be obvious that ab will always be greater than a + b.

For larger numbers, the difference between the sum of digits and the number only grows, as a number abc = a*100 + b*10 + c, abcd = a*1000 + b*100 + c*10 + d, etc.

Proof by exhaustion (via Java code, since this is listed in the programming category):

for (int n = 10; n <= 99; ++n) {

int _n = n;

int sumDigits = 0;

while (_n != 0) {

sumDigits += _n % 10;

_n /= 10;

}

if (n < sumDigits) {

// This code is never reached, since n >= sumDigits for all 10 <= n <= 99

System.out.println(n + " < " + sumDigits);

}

}

What is an initialization statement?

When a declared variable receives a value to hold.

i.e.

int lalalala;

lalalala = 0; //initialization of lalalala

Write a C plus plus program to convert a given number into years weeks and days?

#include<iostream>

void num_to_years_weeks_days(

unsigned num, unsigned& years,

unsigned& weeks, unsigned& days)

{

years = num / 365;

num -= years * 365;

weeks = num / 7;

num -= weeks * 7;

days = num;

}

int main()

{

unsigned years, weeks, days;

unsigned num = 1000;

num_to_years_weeks_days(num, years, weeks, days);

std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl;

num = 12345;

std::cout << num << " days is " << years << " years, " << weeks << " weeks and " << days << " days\n" << std::endl;

}

Write c program to enter a string it has to display with space?

#include
#include

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

int main()
{
string myStr = "";
cout << endl << "Enter your line (to finish press #): ";
getline(cin, myStr, '#');

cout << endl << "You have entered: "" << myStr << """
<< endl;

system("PAUSE");
return 0;

}

Where to you use generics in c?

C doesn't have generics, that's C++.

C program to print 1 12 123 1234?

#include <stdio.h>

int main (void) { puts ("1 22 333 4444 55555"); return 0; }

Why it is advantageous to combine Newton Raphson method and Bisection method to find the root of an algebraic equation of single variable?

An improved root finding scheme is to combine the bisection and Newton-Raphson methods. The bisection method guarantees a root (or singularity) and is used to limit the changes in position estimated by the Newton-Raphson method when the linear assumption is poor. However, Newton-Raphson steps are taken in the nearly linear regime to speed convergence.

In other words, if we know that we have a root bracketed between our two bounding points, we first consider the Newton-Raphson step. If that would predict a next point that is outside of our bracketed range, then we do a bisection step instead by choosing the midpoint of the range to be the next point. We then evaluate the function at the next point and, depending on the sign of that evaluation, replace one of the bounding points with the new point. This keeps the root bracketed, while allowing us to benefit from the speed of Newton-Raphson.

Write a program to print 'hello' in output?

Ah, the infamous "Hello World" program.

I'm assuming you have a compiler (if not Dev-C++ if a good)

the code is as follows:

#include <iostream>

using namespace std;

int main()

{

cout << "Hello World" << endl;

system("PAUSE");

return 0;

}

What is the full form of ivr?

It's an abbreviation for Interactive Voice Response, sometime refered to as IVRS (Interactive Voice Response System). IVR is like a complex answering machine with more than one pre-recorded announcements and with ability to recognize and respond to DTMF key presses of human voice.

IVR DefinitionFrom the link IVR Definition under Related Links below:

"Interactive voice response, or IVR, is a computerized phone system that enables a person, typically a telephone caller, to make a selection from a voice menu. The selection is made using touchphone keypad entries or voice responses. This interaction allows the individual to communicate with the phone system and thus the computer system.

The phone system plays pre-recorded voice prompts and the person typically presses a number on a telephone keypad to select the option associated with the voice prompt."

Example

A caller dials a telephone number that is answered by an IVR system. The IVR system executes an application which is tied to the number dialed DNIS (Dialed Number Identification Service). As part of the application, prerecorded audio files or dynamically generated Text to Speech (TTS) audio explain the options available to the caller. The caller is given the choice to select options using DTMF tones or spoken words. Speech recognition is normally used to carry out more complex transactions and simplifies the application menu structure.

What is the limitation of linear queue and how do you overcome using circular queue?

in linear queue when any element is pop out than we do size-1 value changing ie

like in the pile of coin when we take out the last coin then all changes there places so likewise we have to change the position of each element.....

we can overcome by circular one as we have to change the value of the first and last not the values changes in the array....

but circular queue also had limitation that

either u have to use it as size-1 queue or

it will show you full even though it is empty fully....as first==last...