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

Implementation of general tree?

  • Binary tree is a tree where each node has one or two children.
  • While in case of general tree, a node can have more than two children.
  • A binary tree can be empty, whereas the general tree cannot be empty

What is the advantages of high level languages to low level languages?

High Level Language:

High level language are easier to use and less technical skills are required to do a program. It is very useful where textual data is given priority. Troubleshooting doesn't takes a longer time. We get to know the errors very easily.

Low Level Language:

Low level language are not easily read at a glance and very high technical skill are required to do a program. Troubleshooting takes a longer time. They can produce stunning graphics.

How do you Access MS Access from C?

The following example creates an OracleConnection and sets some of its properties in the connection string. * ** Syntax based on .NET Framework version 1.1 ** #using #using #using using namespace System; using namespace System::Data; using namespace System::Data::OracleClient; __gc class COracleConnection

{ public:

void CreateOracleConnection( )

{ String* myConnString Oracle8i;Integrated Security new OracleConnection( myConnString ); myConnection->Open( ); MessageBox::Show( String::Format( S"ServerVersion: {0}\nDataSource:{1}", myConnection->ServerVersion, myConnection->DataSource ) ); myConnection->Close(); } }; // This is the entry point for this application #ifdef _UNICODE int wmain( void ) #else int main( void ) #endif { COracleConnection *pCOracleConnection = new COracleConnection(); pCOracleConnection->CreateOracleConnection( ); return 0; } You will use Oracle's API. Its called OCI for Oracle Call Interface -- use Google for details about its usage. You can also use OTL, which is the Oracle Template Library. Its much easier to use than OCI. Additionally, you can use embedded sql and precompile this code into pure C using the Oracle Pro*C/C++ precompiler. Sample code exists in ORACLE_HOME/precomp/demo/proc and ORACLE_HOME/rdbms/demo. As Oracle is the largest database company in the world with the largest market share of enterprise s/w, you can bet there is code all over the internet to do what you want to do. Check the forums at otn.oracle.com, google (or other search engine), or asktom.oracle.com. Answer You can also use library such as OCILIB (wraper for OCI) and Libsqlora. The other solution is use UnixODBC for unix programming environtment. Visit www.alldatabaseprogramming.blogspot.com or www.gtkinaction.blogspot.com for further information.

A program to find the LCM of two numbers?

/*

Assuming that by "a shell program", you mean "a program that is run from a shell", and not "a shell script", then this would fit the bill.

Note that it could be optimized in many ways, such as:

- checking only for prime factors

- only counting as high as the square root of the smaller number

*/

#include <stdio.h>

#include <stdlib.h>

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

int val1, val2, n, gcd = 0;

if( argc != 3 ){

fprintf( stderr, "Insufficent arguments. Syntax:\n\tgcf #a #b\n" );

fflush( stderr );

exit( 1 );

}

val1 = atoi( argv[1] );

val2 = atoi( argv[2] );

if( val1 < 2 val2 < 2 ){

printf( "No common factors\n" );

exit( 0 );

}

for( n = 2; n < val1 && n < val2; n++ ) {

if( val1 % n 0 ){

printf( "No common factors\n" );

}else{

printf( "Greatest common factor is %i\n", gcd );

}

return 0;

}

Data organized in ascending or descending oreder?

Data organized in ascending or descending order is called stacking data. Stacking data is usually organized by number or by alphabet.

How can you convert an infix notation to postfix notation?

#include <iostream>

#include <stack>

using namespace std;

int prec (char ch){

// Gives precedence to different operators

switch (ch) {

case '^':

return 5;

case '/':

return 4;

case '*':

return 4;

case '+':

return 2;

case '-':

return 1;

default :

return 0;

}

}

bool isOperand(char ch){

// Finds out is a character is an operand or not

if ((ch>='0' && ch<='9') (ch>='a' && ch<='z'))

return true;

else

return false;

}

string postFix (string infix){

string pfix = "";

stack<char> opstack;

for (int i=0; i<infix.length(); i++){

// Scan character by character

if (isOperand(infix[i]))

{

pfix += infix[i];

}

else if (infix[i] ')')

{

// Retrace to last ( closure

while (opstack.top() != '(')

{

pfix += opstack.top();

opstack.pop();

}

// Remove the '(' found by while loop

opstack.pop();

}

What are C plus plus intrinsic functions?

Most functions are available from libraries, however some functions are built-in to the compiler itself. A built-in function is therefore an intrinsic function.

Some intrinsics are only available as built-in functions while others also have standard function equivalents. You can choose to use some or all intrinsics either by using the #pragma compiler directive or via a compiler optimisation switch, such as /Oi in MSVC++, or indeed both.

Intrinsic functions are typically inline expanded to eliminate the overhead of a function call, and some will also provide information back to the compiler in order to better optimise the emitted code.

Intrinsics affect the portability of code but are generally more portable than inline assembler. Indeed, some architectures do not support inline assembler, thus intrinsics are nothing if not essential where optimal code is a requirement.

Your compiler's documentation should provide a complete list of the intrinsic functions available for each platform it supports, along with the standard function equivalents.

What is the keyword used in C to give space in ASCII?

ASCIIHTMLHTMLDecHexSymbolNumberNameDescription32 20 space

How do you repair an unhandled exception?

You can stop an unhandled exception by handling it. When your program crashes it will tell you exactly where it crashed and what exception it ran into. Dealing with the exception is the hard part. Generally, you want to take one of two approaches. The first is to make sure that the exception cannot happen. You may, for example, have to validate data to make sure that your users aren't allowed to give input which would result in a division-by-zero exception. The second is to allow the exception to be thrown, but use a try-catch block to catch it and print out a useful message instead of crashing. The method you choose will depend on what your program is supposed to do, who is using it, what exceptions are being thrown, where they're being thrown, etc. There's no silver bullet solution for handling an exception.

Write a shell program to check odd or even number?

/*Programming in C...*/

#include


int main(void)
{

int n ;
printf("enter a number :");
scanf("%d",&n);

if(n%2==0)
{
printf("no is even\n");
}
else
printf("no. is odd\n");

return 0;
}

Algoritm for deleting the last element from a list?

Given a list and a node to delete, use the following algorithm:

// Are we deleting the head node?

if (node == list.head)

{

// Yes -- assign its next node as the new head

list.head = node.next

}

else // The node is not the head node

{

// Point to the head node

prev = list.head

// Traverse the list to locate the node that comes immediately before the one we want to delete

while (prev.next != node)

{

prev = prev.next;

}

end while

// Assign the node's next node to the previous node's next node

prev.next = node.next;

}

end if

// Before deleting the node, reset its next node

node.next = null;

// Now delete the node.

delete node;

Why does programmer need variable?

Variables can maintain the same value throughout a program, or they can change values several times, depending on your needs. when you put a variable in a program, the computer recognises the variable and you can change it's value throughout without an error. Note: You can write programs without variables, but their functionality will be quite restricted, like this:

int main (void) { puts ("hello, world"); return 0; }

What are high level programming languages how they differ from assembly languages?

High-level languages are easy to read and write. They are not machine dependent and portable from one computer to another. Assembly languages are machine dependent, easier to read than machine code but it's still not easy to read, and the assembler program translates the assembler program straight into machine code.

Use of nested switch case?

KVM switches are available via hardware and now today over IP software is also available...many switch, keyboard and video combinations are possible.

Input and output statements in C?

For input: scanf("%d",&the value u wanna get into pgm); For output: printf("%d",the value u wanna give to out); Note: u ve to be sure in the letter u put after %.because it ll change depends on variable.eg:int,char,floatdouble,string,decimal,hex,oct..etc Rgds, BM

Write a program to detect duplicate elements in array?

The simplest way of doing this is not very efficient, but provides a quick development time. You want to take all of the elements of the array, add them to a Set, then retrieve them as an array again. Note that this will probably not preserve the order of elements in the array.

{

Object[] originalArray; // let's pretend this contains the data that

// you want to delete duplicates from

Set newSet = new HashSet();

for (Object o : originalArray) {

newSet.add(o);

}

// originalArray is now equal to the array without duplicates

originalArray = newSet.toArray();

}

Now the efficient, and more correct, solution.

This one will create a new array of the correct size without duplicates.

{

Object[] originalArray; // again, pretend this contains our original data

// new temporary array to hold non-duplicate data

Object[] newArray = new Object[originalArray.length];

// current index in the new array (also the number of non-dup elements)

int currentIndex = 0;

// loop through the original array...

for (int i = 0; i < originalArray.length; ++i) {

// contains => true iff newArray contains originalArray[i]

boolean contains = false;

// search through newArray to see if it contains an element equal

// to the element in originalArray[i]

for(int j = 0; j <= currentIndex; ++j) {

// if the same element is found, don't add it to the new array

if(originalArray[i].equals(newArray[j])) {

contains = true;

break;

}

}

// if we didn't find a duplicate, add the new element to the new array

if(!contains) {

// note: you may want to use a copy constructor, or a .clone()

// here if the situation warrants more than a shallow copy

newArray[currentIndex] = originalArray[i];

++currentIndex;

}

}

// OPTIONAL

// resize newArray (using _newArray) so that we don't have any null references

Object[] _newArray = new Object[currentIndex];

System.arraycopy(newArray, 0, _newArray, 0, currentIndex);

}

What is return keyword in c?

return lets you literally return a value from a function. This allows you to define functions like:

int add(int x, int y)

{

return(x + y);

}

int twoplustwo = add(2, 2);

What is primitive system of measurement?

Solar and Lunar cycles. Some cultures used one or the other for the basis of their yearly calendars.

How will you find the location of an element of an array?

Basically,

&array[i];

That is, the memory location for an array object with index i.

Or, you can do:

(array + i);

Why routine operator maintenance is so important?

Intermittent machines are maintained by closely examining them on a regular basis and replacing any damaged parts. Lubrication and coolants are topped off as needed to keep it running at peak performance.

To find whether a number is odd or even?

The following simply uses the definition of "odd" and "even". Do an integer division by 2. If it is divisible (no remainder), it is even. Else, it is odd. Here is some sample code in Java:

System.out.println(myNumber % 2 == 0 ? "It is even" : "It is odd");

Flow chart to reverse digits of numbers?

ALGORITHM REVERSE

INPUT (string)

"STRINGLENGTH() would be a function that returns the lenght of the string"

FOR (i = STRINGLENGTH(string); i >= 0; i--) BEGIN

DISPAY (string[i])

END FOR

END REVERSE

Write a program in c to find transpose of a matrix using functions?

Sorry to delete the previous version of this program, but this one is much more concise and sophisticated. I have written this program for a 3*3 matrix, but if you want to change it, just enter additional variables to store the order of the matrix and then replace the "3"s of the program with them as needed. It's easy. So here we go:

#include

#include

void swap(int *x,int *y);

main()

{

int i,j,k,m,n;

int matrix[3][3];

printf("Enter the matrix: \n\n");

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

{

printf("\nEnter #%d row: ",(i+1));

for (j=0;j<3;++j)

scanf("%d",&matrix[i][j]);

}

printf("\n\n");

for (j=0;j<3;++j)

{

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

if (i>j)

swap(&matrix[i][j],&matrix[j][i]);

}

printf("The transposed matrix is: \n\n");

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

{

for (j=0;j<3;++j)

printf("%4d",matrix[i][j]);

printf("\n\n");

}

}

void swap(int *x,int *y)

{

int t=*x;

*x=*y;

*y=t;

return;

}