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 much space is occupied by an integer pointer float pointer..... n soo on?

The size of a pointer is not dependent on the size of the target integer, float, and so on. Typically, a pointer is 2 bytes (16 bit system), 4 bytes (32 bit system), or 8 bytes (64 bit system).

Note: that's what sizeof is good for

As examples: (for a 32 bit Windows platform)

int a; /* sizeof(a) is 4 */

int* pa; /* sizeof(pa) is 4, and sizeof(*pa) is also 4 */

double d; /* sizeof(d) is 8 */

double* pd; /* sizeof(pd) is still 4, and sizeof(*pd) is 8 */

typedef struct s { /* using alignment option /zp1 */

int a;

double b;

char c[16];

} ss;

ss myss; /* sizeof(myss) is 28 */

ss* pmyss; /* sizeof(pmyss) is still 4, and sizeof(*pmyss) is 28 */

Define parent function?

A parent function refers to the simplest function as regards sets of quadratic functions

121 S ON A C C B?

121 spaces on a Chinese checkers board

What is a c program to implement trapezoidal and Simpson's methods?

ITS EASY...

TRY THIS OUT..

TRAPEZOIDAL METHOD

#include

#include

#include

float valcal(float x){

return (x*x*x);

}

int main(){

float a,b,h,c,I;

int n,i;

printf("THE TRAPEZOIDAL RULE:\n");

printf("---------------------");

printf("\n\n\nEnter the two limits and the no. of divisions:\n");

scanf("%f %f %d",&a, &b, &n);

h=(b-a)/n;

//printf("\nVALUE of h: %f\n", h);

c=a;

I=valcal(a)+valcal(b);

//printf("\nVALUE FOR a: %f\n", valcal(a));

//printf("\nVALUE FOR b: %f\n", valcal(b));

for(i=1;i

c=c+h;

//printf("\nValue of c for loop %d: is %f\n ",i,c);

if(c>=b){

printf("\n\nc>b\n\n");

break;

}

//printf("\nVALUE FOR %f: is %f\n",c, valcal(c));

I=I+(2*valcal(c));

//printf("\nI right now is %f", I);

}

printf("\n\n\nThe integration of x*x*x is: %f",(h*I)/2);

printf("\n\n\n");

system("pause");

}

SIMPSON'S 1/3RD METHOD

#include

#include

#include

float valcal(float x){

return (1/(1+x*x));

}

int main(){

float a,b,h,c,I;

int n,i;

printf("THE SIMPSON'S ONE-THIRD RULE:\n");

printf("------------------------------");

printf("\n\n\nEnter the two limits and the no. of divisions:\n");

scanf("%f %f %d",&a, &b, &n);

h=(b-a)/n;

//printf("\nVALUE of h: %f\n", h);

c=a;

I=valcal(a)+valcal(b);

//printf("\nVALUE FOR a: %f\n", valcal(a));

//printf("\nVALUE FOR b: %f\n", valcal(b));

for(i=1;i

c=c+h;

//printf("\nValue of c for loop %d: is %f\n ",i,c);

if(c>b){

printf("\n\nc>b\n\n");

break;

}

//printf("\nVALUE FOR %f: is %f\n",c, valcal(c));

if(i%2==0)

I=I+(2*valcal(c));

else

I=I+4*valcal(c);

//printf("\nI right now is %f", I);

}

printf("\n\n\nThe integration of x*x*x is: %f",(h*I)/3);

printf("\n\n\n");

system("pause");

}

NEED MORE HELP...

MAIL ME YOUR PROB... SEE YA

Can you use commit statement after truncate?

You can use COMMIT any time, but it is not necessary after TRUNCATE TABLE.

How do you break the infinite loop program in turbo c plus plus without break key?

In short, you don't. By definition, an infinite loop is one that has no exit condition. For example:

while( 1 );

When execution reaches this line, the program will get no further. It will continually execute this same line of code because the only way for this loop to exit is when the literal constant 1 becomes the literal constant 0 -- which would clearly be impossible.

By the same token, the following lines are also infinite loops:

do while( 1 );

for(;;);

Infinite loops of this kind are completely useless in production code. Apart from the fact they do nothing remotely useful, an infinite loop renders the program completely invalid. And yet we hear the term infinite loop being used in code all the time.

The truth is that while we do use the term infinite loop, it is not strictly infinite. What we really mean is that although the loop statement needn't have an exit condition, the body of the loop does!

By way of an example, consider the following infinite loop:

while( 1 )

{

if( !rand() )

break;

}

Here, the loop statement is clearly infinite, but the body contains the all-important exit condition. In this case, the loop continually produces random numbers in the range 0 to 32767. If the number is zero, then control passes to the break statement at which point the loop ends and execution continues at the statement following the closing brace of the loop. Thus on every loop there's a 1 in 32768 chance the loop will end. There's a remote possibility the loop may never end however it's highly unlikely. Note that in its current form, the random numbers will produce the same sequence over an over and the loop will therefore execute the same number of times every time the program is run. But even if we seed the random numbers to produce a different sequence each time, the loop will exit after just a few seconds at most. The odds of never ever producing a zero are remote in the extreme.

So that's the so-called infinite loop -- which is not really infinite after all. But to answer the question, we break out of an infinite loop by providing at least one exit condition within the body of the loop. If the program is to be run within an event-driven environment (such as Windows), we might periodically test the message queue to see if a specific key sequence is pending (such as ESC) and prompt the user to save the current state of the loop so that it can continue at a later date before gracefully exiting the loop. By the same token, we should also check for a program exit message (perhaps the user clicked the close window button, or even chose to shutdown Windows in the middle of the loop) and we must cater for those eventualities too.

Ultimately, how you exit an infinite loop will depend entirely upon the purpose of the loop. There is no one-size-fits-all solution. But there must be at least one exit condition that must logically fire at some point in time. If not, the loop is truly infinite and will completely invalidate your program.

What is the 4th derivative of the position function?

Distance f(x) = x(t) = 1/2at2+vit+xi Velocity f'(x) = v(t) = dx/dt=at +vi Acceleration f''(x) = a(t) = dv/dt Jerk f'''(x) = j(t) = da/dt The fourth derivative is not universally accepted, but some have called it "snap", and the fifth and sixth derivatives "crackle" and "pop" respectively. Snap f(4)(x) = s(t) = dj/dt Crackle f(5)(x) = c(t) = ds/dt Pop f(6)(x) = p(t) = dc/dt

What is dos.h?

A non-standard C header file that contained functions specific to accessing functions of MS-DOS. There is no need to use this header file, as there are standard libraries included in all major compilers that replace the functions in DOS.H.

How do you write a header for a 128x128x128 dds volume texture file with no mipmaps and does it have to be written in binary?

According to the documentation on MSDN, the following code should create an uncompressed volume texture DDS file that's 32x32x32 in size. Re-scale as you see fit. Note: a 128x128x128 RGBA texture will take up 8 MB of VRAM! #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define DDSD_CAPS 0x00000001 #define DDSD_HEIGHT 0x00000002 #define DDSD_WIDTH 0x00000004 #define DDSD_PITCH 0x00000008 #define DDSD_PIXELFORMAT 0x00001000 #define DDSD_MIPMAPCOUNT 0x00020000 #define DDSD_LINEARSIZE 0x00080000 #define DDSD_DEPTH 0x00800000 #define DDPF_ALPHAPIXELS 0x00000001 #define DDPF_FOURCC 0x00000004 #define DDPF_RGB 0x00000040 #define DDSCAPS_COMPLEX 0x00000008 #define DDSCAPS_TEXTURE 0x00001000 #define DDSCAPS_MIPMAP 0x00400000 #define DDSCAPS2_CUBEMAP 0x00000200 #define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400 #define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800 #define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000 #define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000 #define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000 #define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000 #define DDSCAPS2_VOLUME 0x00200000 int depth = 32; int width = 32; int height = 32; unsigned int header[32]; int main( int argc, char * argv[] ) { if( !argv[1] !strstr( argv[1], ".dds" ) ) { fprintf( stderr, "Usage: noise output.dds\n" ); return 1; } unsigned int cnt = width*height*depth*4; unsigned char * buf = new unsigned char[ cnt ]; while( cnt-- ) { buf[cnt] = rand()>>7; } memset( header, 0, sizeof( header ) ); header[0] = ' SDD'; header[1] = 124; header[2] = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_DEPTH | DDSD_PITCH; header[3] = height; header[4] = width; header[5] = width*4; header[6] = depth; header[19] = 32; header[20] = DDPF_RGB|DDPF_ALPHAPIXELS; header[22] = 8; header[23] = 0xff0000; header[24] = 0xff00; header[25] = 0xff; header[26] = 0xff000000; header[27] = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX; header[28] = DDSCAPS2_VOLUME; FILE * f = fopen( argv[1], "wb" ); if( !f ) { fprintf( stderr, "can't create: %s\n", argv[1] ); return 1; } fwrite( header, 4, 32, f ); fwrite( buf, 1, width*height*depth, f ); fclose( f ); fprintf( stderr, "wrote %s\n", argv[1] ); return 0; }

What to do if it says Missing before statement line 2 file Code?

If it says Missing before statement line 2 file Code you just need to include ; before the statement.

Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account?

// ASSIGNMENT 3.cpp : Defines the entry point for the console application.

//

#include

"stdafx.h"

#include

"conio.h"

#include

<iostream>

using

std::fixed;

using

namespace std;

class

Account

{

public: Account( double ); // constructor initializes balance

void

credit( double ); // add an amount to the account balance bool debit( double ); // subtract an amount from the account balance

void setBalance( double ); // sets the account balance

double getBalance(); // return the account balance

private: double balance;

// data member that stores the balance

// Account constructor initializes data member balance

Account::Account(

double initialBalance )

{

// if initialBalance is greater than or equal to 0.0, set this value

// as the balance of the Account

if ( initialBalance >= 0.0 )

balance = initialBalance;

else // otherwise, output message and set balance to 0.0

{

cout <<

"Error: Initial balance cannot be negative." << endl;

balance = 0.0;

}

// end if...else

}

// end Account constructor

// credit (add) an amount to the account balance

void Account::credit( double amount )

{

balance = balance + amount;

// add amount to balance

}

// end function credit

// debit (subtract) an amount from the account balance

// return bool indicating whether money was debited

bool Account::debit( double amount )

{

if ( amount > balance ) // debit amount exceeds balance

{

cout <<

"Debit amount exceeded account balance." << endl;

return

false;

}

// end if

else // debit amount does not exceed balance

{

balance = balance - amount;

return true;

}

// end else

}

// end function debit

// set the account balance

void Account::setBalance( double newBalance )

{ balance = newBalance;

}

// end function setBalance

// return the account balance

double Account::getBalance()

{

return balance;

}

// end function getBalance

};

// end class Account

class

SavingsAccount : public Account

{

public:

// constructor initializes balance and interest rate

SavingsAccount(

double, double );

double calculateInterest(); // determine interest owed

private:

double interestRate;

SavingsAccount::SavingsAccount(

double initialBalance, double rate ) : Account( initialBalance ) // initialize base class

{

interestRate = ( rate < 0.0 ) ? 0.0 : rate;

// set interestRate

}

// end SavingsAccount constructor

// return the amount of interest earned

double SavingsAccount::calculateInterest()

{

return getBalance() * interestRate;

}

// end function calculateInterest // interest rate (percentage) earned by account

};

// end class SavingsAccount

class

CheckingAccount : public Account

{

public:

// constructor initializes balance and transaction fee

CheckingAccount(

double, double );

void

credit( double ); // redefined credit function

bool debit( double ); // redefined debit function

private:

double transactionFee; // fee charged per transaction

// utility function to charge fee

void

chargeFee();

CheckingAccount::CheckingAccount(

double initialBalance, double fee )

: Account( initialBalance )

// initialize base class

{

transactionFee = ( fee < 0.0 ) ? 0.0 : fee;

// set transaction fee

}

// end CheckingAccount constructor

// credit (add) an amount to the account balance and charge fee

void CheckingAccount::credit( double amount )

{

Account::credit( amount );

// always succeeds

chargeFee();

}

// end function credit

// debit (subtract) an amount from the account balance and charge fee

bool CheckingAccount::debit( double amount )

{

bool success = Account::debit( amount ); // attempt to debit

if

( success ) // if money was debited, charge fee and return true

{

chargeFee();

return

true;

}

// end if

else // otherwise, do not charge fee and return false

return false;

}

// end function debit

// subtract transaction fee

void CheckingAccount::chargeFee()

{

Account::setBalance( getBalance() - transactionFee );

cout <<

"$" << transactionFee << " transaction fee charged." << endl;

}

// end function chargeFee

};

// end class CheckingAccount

int

_tmain(int argc, _TCHAR* argv[])

{

Account account1( 50.0 );

// create Account object

SavingsAccount account2( 25.0, .03 );

// create SavingsAccount object

CheckingAccount account3( 80.0, 1.0 );

// create CheckingAccount object

cout << fixed << setprecision ( 2 );

// display initial balance of each object

cout <<

"account1 balance: $" << account1.getBalance() << endl;

cout <<

"account2 balance: $" << account2.getBalance() << endl;

cout <<

"account3 balance: $" << account3.getBalance() << endl;

cout <<

"\nAttempting to debit $25.00 from account1." << endl;

account1.debit( 25.0 );

// try to debit $25.00 from account1

cout <<

"\nAttempting to debit $30.00 from account2." << endl;

account2.debit( 30.0 );

// try to debit $30.00 from account2

cout <<

"\nAttempting to debit $40.00 from account3." << endl;

account3.debit( 40.0 );

// try to debit $40.00 from account3

// display balances

cout <<

"\naccount1 balance: $" << account1.getBalance() << endl;

cout <<

"account2 balance: $" << account2.getBalance() << endl;

cout <<

"account3 balance: $" << account3.getBalance() << endl;

cout <<

"\nCrediting $40.00 to account1." << endl;

account1.credit( 40.0 );

// credit $40.00 to account1

cout <<

"\nCrediting $65.00 to account2." << endl;

account2.credit( 65.0 );

// credit $65.00 to account2

cout <<

"\nCrediting $20.00 to account3." << endl;

account3.credit( 20.0 );

// credit $20.00 to account3

// display balances

cout <<

"\naccount1 balance: $" << account1.getBalance() << endl;

cout <<

"account2 balance: $" << account2.getBalance() << endl;

cout <<

"account3 balance: $" << account3.getBalance() << endl;

// add interest to SavingsAccount object account2

double interestEarned = account2.calculateInterest();

cout <<

"\nAdding $" << interestEarned << " interest to account2."<<endl;

account2.credit( interestEarned );

cout <<

"\nNew account2 balance: $" << account2.getBalance() << endl;

return 0;

}

// end main

Can a parent class access the functions of child class?

no, Parent class can not access the members of child class ,but child class can access members of parent class

When a value is read from a memory in c language and preserved this process is called?

Saving. Values can be saved by writing them to non-volatile memory such as a hard-disk file.

Write a program in C which has an integer array and its size as parameter and returns the sum of the values of the elements of the elements of the array Write a main function and show its usage?

#include

using std::cin;

using std::cout;

using std::endl;

int main()

{

int sizeOfArray = 5;

int myArray[] = {0};

cout << "Enter elements of array" << endl;

for (int i = 0; i < sizeOfArray; i++)

{

cin >> myArray[i];

}

int sum = 0;

for (int j = 0; j < sizeOfArray; j++)

{

sum += myArray[j];

}

cout << endl << "Sum of " << sizeOfArray << " is: " << sum;

cin.get();

return 0;

}

What happened to programer c?

programmer c is no more do not question or...nighty night

How do you repair the black screen on turbo c?

With conio.h you can change the background color (function textbackground).

What statement is used to skip a part of loop?

The continue statement is used to skip the balance of a loop.

What does printf function return?

Two possibilities: on success, it'll return the amount of characters printed. On failure, a negative number is returned.

Where system header files are stored in c?

This depends on what compiler you are using. For the most common compilers (including gcc) on a *nix system, most standard header files will be either in /usr/include or /usr/local/include. Check your compiler's documentation for how to check and/or modify the search paths.