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 type of loop always execute at least once?

A do-while loop always executes at least once, and works like this:

do

{

//code, such as incrementing a value, printing text, etc.

} while (expressionToEvaluate);

a perfect example of this would be something like:

<code>

int i = 10;

int counter = 0;

do

{

counter+=i;

i--;

} while (i > 0);

</code>

C memory model?

Memory Organization for a process

--------------------------------------------

CODE SEGMENT: contains executable code

DATASEGMENT:contains static and global variable

HEAP SEGMENT:Dynamically allocated variables will be in heap

STACK SEGMENT:For local or automatic variables

PREM G

premgnath@gmail.com

What is difference between memcpy and memmove?

Its similar to typing without insert key ON and OFF

str1="strings are good");

memmove(str1+8,str1+11,4);

returns------ strings are are good

memcpy(str+8,str1+11,4)

returns------ strings are read

memcpy - just copies from source to destination.

memmove - copies from source to destination if buffers overlap, every character is read before another character is written to the same location

memcpy() copies the bytes of data between memory blocks. If the block of memory overlaps, the function might not work properly. Use memmove() to deal with overlapping memory blocks.

memmove() is very much like memcpy() but very flexible as it handles overlapping of memory blocks.

How is a C program rum?

C-source program doesn't rum, you have to compile and link it. The executable rums like any other binary program.

What relationship does a stack and recursion have?

Local variables and formal parameters are stored on the stack. Recursion is the process of calling a function from within itself, saving local variables and formal parameters. Since the stack is a recursive last-in-first-out data structure, the best place to place variables for each step is on the stack.

The classic example is N Factorial...

int nfact (int n) if (n == 2) return n else return nfact (n - 1);

This example only has one formal parameter. If you called it as nfact(10), by the time n reached 2 there would be 9 return addresses and 9 formal parameters on the stack, and nfact() would have been called 9 times. At that point, the stack unwinds due to the return n statement, and the final result is 3628800.

A simplified picture of the stack at n==2 would look like ...

10
return address of caller
9
return address in nfact
8
return address in nfact
7
return address in nfact
6
return address in nfact
5
return address in nfact
4
return address in nfact
3
return address in nfact
2
return address in nfact

More complex code could easily create and manipulate local variables, so long as they were on the stack. Each recursive instance, then, would be properly isolated from its parent and child, and they would not interfere with each other.

Is The controlling expression for a switch statement can be a char?

char is actually integer, even so they are represented with letters. Anyway, yes you can use the controlling expression of type char in switch statements.

Want context free grammar for c language compiler?

we use context free grammer in compiler consctrtion to cheack the validati of input in parsing.

What is Efficiency of Binary Search tree operations?

If it is an unbalanced binary tree, O( ln( n ) / ln( 2 ) ) is best-case. Worst case is O( n ).

If it is balanced, worst case is O( ln( n ) / ln( 2 ) ).

Why the 0 and 1 are binary numbers?

The term binary means based on two numbers only. It would be possible to use any two numbers for a binary system, however, since 0 and 1 are the first two numerals, it was considered reasonable to use those. It could just as easily have been 1 and 2. The advantage of a binary system is that it is easily converted to an electrical circuit state; one number means on, the other number means off. That makes it useful for computers, which are based on electrical circuits.

How do you implement c program for conditional compilation?

Conditional compilation is achieve through preprocessor directives. First, define the preprocessor symbols upon which conditional compilation depends, then test them using #if and #else preprocessor directives. A #endif directive indicates the end of the nearest enclosing conditional block, thus conditional blocks may be nested.

The following example demonstrates how we can conditionally define debug or production code based upon the absence or existence of the NDEBUG symbol:

#ifdef NDEBUG

/* all C code within this block is compiled when NDEBUG is defined (production code) */

#else

/* all C code within this block is compiled when NDEBUG is not defined (debug code) */

#endif

Note that the NDEBUG symbol is typically defined via the command line, however symbols can also be defined or undefined via the source using the #define and #undefine directives. For instance, header files typically require guards to protect against being included more than once in a compilation and preprocessor directives provide the conventional means of ensuring that is the case:

// myheader.h

#ifndef _MYHEADER_H_

#define _MYHEADER_H_

// all header code goes here...

#endif

By convention, preprocessing symbols (macros) are defined with all uppercase and are intentionally ugly to avoid any confusion with C identifiers. Header guards must be unique to each header thus they are typically based upon the header file name itself.

Where is a data statement usually placed in a basic program?

Anywhere really. A data statement (or REM statement) - can be placed anywhere within the program, because the operating system ignores all REM statements.

Write c program to find odd or even no?

For any number n you could use

* (n % 2 == 0), which would be true for an even number, false for odd For an integer i, a simpler method would be

* (i & 1), which would be true for an odd number, false for even

Is it possible to access databases through C-CPP and if so how?

Most database vendors offer an API for this purpose. The usage will vary by vendor, but generally you open a connection, query (or runcommand), check or step through results, close connection. In the MS Windows environment, you can also use ODBC (Open Database Connectivity), which is an API that abstracts (no, its not C++ classes) the database, its tables, and its query language. You still have to install a vendor specific ODBC driver, and a vendor specific database client, so you still need to consult the vendor documentation. The procedure is similar to the non ODBC solution - you open the connection, query it, step through the results cursor, and close the connection.

Is selection sort and tournament sort are same?

No. Tournament sort is a variation of heapsort but is based upon a naive selection sort. Selection sort takes O(n) time to find the largest element and requires n passes, and thus has an average complexity of O(n*n). Tournament sort takes O(n) time to build a priority queue and thus reduces the search time to O(log n) for each selection, and therefore has an average complexity of O(n log n), the same as heapsort.

What is the bitwise OR of 35 with 7 in C?

35 OR 7 is 39.

To see how this works, write the values in binary, one directly above the other:

00100011 (35)

00000111 (7)

Each column provides the two input operands for the OR operator. The output is derived from the following truth table:

0 or 0 = 0

0 or 1 = 1

1 or 0 = 1

1 or 1 = 1

Thus when the column has two 0s, we output a 0, otherwise we output a 1. Repeating this for all columns we find the following output:

00100111

Converting this to decimal we can see that 35 OR 7 must be 39.

What are the differences of turbo c plus plus and mother program?

No idea what mother program is, but I assume you mean how does Turbo C++ compare to the ISO C++ standard. The last version of Turbo C++ came out in 2006 and was compliant with the standard at that time. However, Embarcadero (the current owners) no longer support Turbo C++, thus it no longer complies with the current ISO standard.

How can you create a virtual copy constructor?

You cannot. Constructors are specific to the class in which they are declared. They cannot be inherited and so they cannot be virtual.

1 What are the main advantages from using high-level language constructs?

Easy to test program

Easier to implement programming solution

Reduce the repeating code

Easy to change and modify program

Increase the productivity

What is the least common multiple of decimals and fractions in C?

To calculate the least common multiple (lcm) of decimals (integers) and fractions you first need to calculate the greatest common divisor (gcd) of two integers:

int gcd (int a, int b) {

int c;

while (a != 0) {

c = a;

a = b % a;

b = c;

}

return b;

}

With this function in place, we can calculate the lcm of two integers:

int lcm (int a, int b) {

return a / gcd (a, b) * b;

}

And with this function in place we can calculate the lcm of two fractions (a/b and c/d):

int lcm_fraction (int a, int b, int c, int d) {

return lcm (a, c) / gcd (b, d);

}

Write a function in c that returns the largest value stored in an array-of-int Test the function in a simple program?

int max(int arr[], int arrSize)
{
int maximum = arr[0];
for (int i = 0; i < arrSize; i++)
{
if (maximum < arr[i])
{
maximum = arr;

}

}

return maximum;

}

What does int mean in clinical setting?

It stands for intermittent needle therapy. It is a peripheral intravenous access site used to administer medications. It remains in the hospitalized client during their entire stay, in case emergency access is needed.