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 maximum can you allocate in a single call to malloc?

I believe you can attempt to allocate as much as you want, but if you try to take more physical memory than your machine has then malloc will instead return a null pointer

What is algorithm to calculate the factorial of an user given number?

Note: The recursive portions of this code can use a lot of stack space. You may need to tell your linker to allocate more space to prevent a stack overflow exception.

To calculate the factorial of a user given number, simply multiply all of the integers between 2 and that number, inclusive, together. There are two fundamental algorithms; iterative and recursive...

Iterative uses a loop of some sort to iterate through each multiplier and multiply that to the running product.

These examples were developed and checked on the Microsoft Windows SDK 7. Portable compilers might not like the 64-bit long long data type.

/* Microsoft 32-bit iterative */

unsigned long NFactLongIterative (unsigned long N) {

unsigned long result = N;

if (N < 2) return 1;

if (N 2) {

decimal_initialize (d, 2);

return;

}

while (N > 2) {

decimal_multiply (d, N);

N--;

}

return;

}

Main line code, showing full functionality

#include

... all of the above routines are inserted here

/* Example main line */

/* Generates all variations to show differences in results */

int main (int argc, char *argv[]) {

int N;

decimal Decimal = {2, NULL};

if (argc < 2) {

fprintf (stderr, "Usage: factorial N\n");

return 1;

}

N = atoi (argv[1]);

printf ("Long: %u! = %u\n", N, NFactLongIterative (N));

printf ("LongLong: %u! = %I64u\n", N, NFactLongLongIterative (N));

printf ("Recursive: %u! = %I64u\n", N, NFactLongLongRecursive (N));

printf ("Double: %u! = %.0f\n", N, NFactDouble (N));

/* note: arbitrary is exact - if the others don't match, arithmetic overflow occurred */

printf ("Arbitrary: %u! = ", N);

decimal_NFactIterative (&Decimal, N);

decimal_print_digits (&Decimal, TRUE);

return 0;

}

What is the difference between null in c and in oracle?

A NULL in C is a pointer with 0 value, which cannot be a valid address.

A null in Oracle is the condition of not having a value, such as a field in a row being null, meaning that it does not have a value. This is not the same as zero - zero and null are two different things.

Note, however, that Oracle does not differentiate between a null and a zero length string. This was an error in non-ANSI implementation made many years ago, but it has persisted because fixing it would impact too much "running" code.

How do you implement selection sort in c with graphics?

Selection sort has the following implementation:

// sort an array if integers of length size in ascending order using selection sort algorithm:

void selection_sort (int a[], unsigned size) {

unsigned i, max;

while (size > 1) {

max = 0;

for (i=1; i!=size; ++i) if (a[i] > a[max]) max = i;

swap (a[max], a[--size]);

}

}

What is a however statement?

A however statement is a statement that says for example, Cafeteria rules are stupid; however, they have been improving the way the cafeteria runs

Write a program to sort an array using quick sort?

# include <stdio.h> void quicksort(int a[],int st,int end); main() { int n,i,b[10],c[10]; printf("Enter the number of elements"); scanf("%d",&n); printf("Enter the elements 1 by 1 \n"); for(i=0;i<n;i++) { scanf("%d",&b[i]); c[i] = b[i]; } quicksort(b,0,n-1); printf("\tQUICK SORT\n"); printf("\t**********\n\n"); printf("\tNumbers \tSorted List\n"); printf("\t******** \t***********\n"); for(i=0;i<n;i++) printf("\t%d\t\t%d\n",c[i],b[i]); } void quicksort(int a[],int st,int end) { int elt,low,high; low = st; high = end; elt = a[st]; while (st < end) { while ((a[end] >= elt) && (st < end)) end--; if (st != end) { a[st] = a[end]; st++; } while ((a[st] <= elt) && (st < end)) st++; if (st != end) { a[end] = a [st]; end--; } } a[st] = elt; elt = st; st = low; end = high; if ( st < elt) quicksort(a,st,elt-1); if (end > elt) quicksort(a,elt+1,end); } Enter the number of elements6 Enter the elements 1 by 1 34 12 9 0 45 123 QUICK SORT ********** Numbers Sorted List ******** *********** 34 0 12 9 9 12 0 34 45 45 123 123

Difference between parse tree and syntax tree?

Parse trees (also known as Concrete Syntax Trees) contain every token of the input as a leaf, and the interior nodes are nonterminals in the grammar used to parse.

Abstract Syntax Trees omit much of the detail that would be present in a CST. There are still leaf nodes when the associated tokens are information-bearing (such as identifiers and literals), but, for example, keywords and punctuation are not present in an AST. The interior nodes represent language constructs as defined by the grammar. An AST for an "if" statement (for example) would consist of one node to represent the "if" construct, and two or three subtrees, one for the "if" condition and another one or two for the "the" and optional "else" parts. The CST for such a construct would also contain the "if"/"then"/"else" keywords, such that you could walk the tree to obtain the original token sequence.

Write a program to find factorial of number?

#include<stdio.h>

#include<conio.h>

int main()

{

int i,n,fact=1;

printf(" Enter number to find factorial\n");

scanf(" %d",&n);

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

fact=fact*i;

printf("factorial of%d=%d\n",n,fact,);

return 0;

}

Write a program to swap 2 variables with out using 3rd variable through cout?

#include <iostream>

using namespace std;

int main()

{

int a, b;

cin >> a;

cin >> b;

a = a * b;

b = a / b;

a = a / b;

cout << a << " " << b;

char wait;

cin >> wait;

return 0;

}

Write a program defind the sum of dijit of a number?

Void main ()

{

Int n, r, s = 0 ;

Printf (" Enter the number")

Scanf ("% d", & n);

While (n! = 0)

{

r = n%/10;

s = s+r;

n = n/10;

s = s+r;

n = n/10

}

Printf ("sun of the dijit of a no. is % d; s)

What is the Code of expansion of sinx in series in C language?

/*

Aim: Program to Find Value of sin(x) using Expansion Series Given Below:

sin(x) = x - x3/3! + x5/5! - x7/7!........

Developer: Devharsh Trivedi

Web: www.knowcrazy.com

*/

#include <stdio.h>

#include <math.h>

main()

{

float base, pwr, sum, c=1, m=2, i=3, g, h;

printf("\nEnter the base value: ");

scanf("%f", &base);

printf("\nEnter the power value: ");

scanf("%f", &pwr);

sum = base;

ab:

m = m * i;

h = pow(-1, c);

g = pow(base, i);

sum = sum + (h * g) / m;

i = i + 2;

c++;

m = m * (i - 1);

if (i <= pwr)

goto ab;

printf("\n\nSum = %f", sum);

getch();

}

If structure is arraythen an individual array element can be accessed by writing a variable?

A structure is not an array. Individual array elements are accessed through a number, called a "subscript". This subscript can be a constant, or a variable, or any expression that can be evaluated to give an integer.

A structure is not an array. Individual array elements are accessed through a number, called a "subscript". This subscript can be a constant, or a variable, or any expression that can be evaluated to give an integer.

A structure is not an array. Individual array elements are accessed through a number, called a "subscript". This subscript can be a constant, or a variable, or any expression that can be evaluated to give an integer.

A structure is not an array. Individual array elements are accessed through a number, called a "subscript". This subscript can be a constant, or a variable, or any expression that can be evaluated to give an integer.

Write a program to calculate the sum of two numbers in unix?

$vi sum.sh

echo "enter the 1st no."

read num1

echo "enter the 2nd no."

read num2

sum= 'expr $num1 + $num2'

echo "sum of the numbers is $sum"

Why was Unicode created?

256 different characters is not enough

Unicode enables the reliable store most of the world's characters in a (2 byte) fixed width mode with 65,564 characters.

What happens with the EOF or end of file condition?

In C++ EOF is a special function which will return nonzero when there is no more data to be read. In C++ nonzero means true, the alternative to nonzero is zero which means false.

What is a fixed loop?

a fixed loop is obviously a loop that is fixed ;D

What is the advantage of iterative deepening search over depth-first?

Iterative deepening effectively performs a breadth-first search in a way that requires much less memory than breadth-first search does.

So before explaining the advantage of iterative deepening over depth-first, its important to understand the difference between breadth-first and depth-first search. Depth first explores down the tree first while breadth-first explores all nodes on the first level, then the second level, then the third level, and so on.

Breadth-first search is ideal in situations where the answer is near the top of the tree and Depth-first search works well when the goal node is near the bottom of the tree. Depth-first search has much lower memory requirements.

Iterative deepening works by running depth-first search repeatedly with a growing constraint on how deep to explore the tree. This gives you you a search that is effectively breadth-first with the low memory requirements of depth-first search.

Different applications call for different types of search, so there's not one that is always better than any other.

Why does this line of code always assign balance as 0?

Sorry, but I cannot answer this without actually seeing the line in question.

What is char far datatype in c language?

The far memory type may be used for variables and constants. This memory is accessed using 24-bit addresses and may be on-chip or external.

  • For variables, far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Variables declared far are located in the HDATA memory class.
  • For constants (ROM variables), far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Constant variables declared far are located in the HCONST group.

Declare far objects as follows: unsigned char farfar_variable; unsigned char const farfar_const_variable;

Why matrice's definition includes rectangular array instead of array?

Matrices itself is a combination of rows and columns.we can not use one-dimenssional array to save the values of matrices.instead we use the rectangular array which contains rows and columns.thats it.

How can you free alocated memory using c?

The answer is in the question: use function free.

What is magic number in c programming?

The term "magic" has its place in programming history, and generally referred to something that is either understood by those who are experts, or understood by no one, as to How It Works.

Magic numbers in C and other programming languages today have a number of meanings:

- a constant value used to identify a protocol or file formats (file signatures);

- unique identifiers unlikely to be mistaken to mean other things;

- values whose usages are unexplained.

Some interesting examples of magic numbers include:

- Java bytecode files start with 0xCAFEBABE, but compressed with "Pack200" the code becomes 0xCAFED00D (this is magical);

- image files start with unique identifiers like "GIF89a", "GIF87a", or begin and end with unique values;

- Mark Zbikowski designed the EXE file format, which starts with MZ (0x5A 0x4D), ensuring at least part of his name was burned into the annals of history;

- On older systems, newly allocated or freed memory was marked with the 32-bit hexadecimal value 0xDEADBEEF, and initializing memory came to be known in some circles as "deadbeefing the memory" or "the memory is deadbeef".

The related Wikipedia link below has a glut of information to sink your brain info regarding magic numbers.