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

Write a algorithm to print all even numbers in descending order?

AnswerIf A=10, B=2...

Then the algoritm is :-

STEP1 : START.

STEP2 : A=10.

STEP3 : B=02.

STEP4 : C=A-B.

STEP5 : PRINT C.

STEP6 : STOP.

AnswerYou cannot print every even number in descending order, because there is no greatest even number. Or you want something like this:

infinity

infinity-2

infinity-4

Answerstep 1: start

step 2: Input N

step 3: If N<=1, go to step 5

step 4: if N%2=0, Print N

N=N-1, go to step 3

step 5: End

How do you write a c program sum of all elements from a two dimensional (2D) array?

#include #include voidmain() { int a[10]; int i,sum=0; int *ptr; printf("Enter 10 elements:n"); for(i=0;i<10;i++) scanf("%d",&a[i]); ptr = a; /* a=&a[0] */ for(i=0;i<10;i++) { sum = sum + *ptr; //*p=content pointed by 'ptr' ptr++; } printf("The sum of array elements is %d",sum); }

Difference between include header file in C and import in java?

A) #include makes the C/C++ compiler to physically copy the entire header file code into the 'Cor C++' programs, Thus the program size will increase unnecessarily and hence it takes more memory and memory processor time.
Where as import statement makes the JVM to go to Java Library, execute the code there and substitute the result into the Java program "Here no code is copied"...................................




During compilation an .obj file will be light weight in c where as heavy during execution, which is constrant to the .class file




Sandeep Bandari (Chandurthy,9704740271)

Can a reserved word be used as an identifier name?

Identifiers are a bit more generic in the context of programming.

If you mean, in terms of the C languages (C, C++, C#), the question is the reverse...keywords may NOT be used as identifiers.

For example, you cannot use keywords such as "int", "float", "double", etc. as the names of variables or objects.

5 steps of the program development process?

Programming is a problem-solving activity. A person with good problem solving skills will tend to be a good programmer. To develop this skill, a programmer must practice the following steps:

  1. Problem Analysis
  2. Setting up an algorithm
  3. Coding
  4. Encoding
  5. Running, testing and debugging
  6. Documentation

Write a prog to find length of string using strlen function?

void main()

{

char str1[30];

char str2[30];

int len1,len2;

printf("Enter string1......:");

gets(str1);

printf("Enter string2......:");

gets(str2);

len1=strlen(str1);

len2=strlen(str2);

printf("%s length = %d",str1,len1);

printf("%s length = %d",str2,len2);

}

How to convert From human language to computer language?

Depending on what you're looking at, you may not be able to. My suggestions would be to find the appropriate program used to edit the type of file you're looking at, or to try to find a decompiler for the programming language the file corresponds to.

How do you write linked list program?

a Linked List is a Linear collection of self refrential -class objects, called Nodes that's in General. but if you are using Java You can build it Like That.. http://www.cs.fiu.edu/~weiss/dsj3/code/weiss/nonstandard/LinkedList.java if you are using C++ this Link will be helpful http://richardbowles.tripod.com/cpp/linklist/linklist.htm it covers the ideas of a linked list that what i used (C++,Java) i don know what about C# maybe other contributors can help...

Program to print sorting of an array in clanguage?

/* PROGRAM TO SORT ARRAY ELEMENTS USING BUBBLE SORT*/ #include #include void main() { int i,j,n,t,a[50]; clrscr(); printf("ENTER THE ARRAY SIZE:\n"); scanf("%d",&n); printf("ENTER THE ARRAY ELEMENTS:\n"); for(i=0;i

Difference between syntax error and runtime error?

Syntax error can be found during compilation. Runtime error can be found only when you are trying to execute your program.

Syntax errors are those which are caused by incorrect usage of the programming language. All programming language compilers are designed to detect and report such errors done by the programmer

Runtime errors are those which are caused by incorrect usage of programming logic. for example a runtime divide method will throw a run time error if the divisor is '0' because numerically you cannot divide a number by 0

How do you start array list from 1?

Array indices are zero-based because the first element is at offset zero from the start of the array. There is no such thing as a one-based array in C. Some other languages do allow you to specify the base of an array, but converting a non-zero-based index to a zero-based index adds a runtime overhead to the implementation.

Strengths and weaknesses of the C language?

  • Well, I program in C++, and really isn't something you can't do. At least it is the most flexible programming language. If you want something flexible, take C. And I'll give you some more advice: Take C++. C has some really annoying things that C++ fixes. There really aren't limitations. And C and C++ are good. They're the ones you'd start out with, and the ones I'm continuing in, but if you really liked classes in C, you could try Java. It's really class - based.

    -YMT Yusuf E

What is queue explain the basic element of queue?

The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Following are the types of queue: Linear queue Circular queue Priority queue Double ended queue ( or deque )

How many bytes in long?

The set of datatypes and the definition of each member is dependent on hardware, the language standard, and the language implementation. Not knowing which language the question relates to is particularly limiting.

In Java, a long consists of 8 bytes. This is also generally true for C and C++, depending upon the compiler used. See the related links for further details.

What are the four types of grammars used in compiler?

-Single pass compiler

-Multi pass compiler

-Cross compiler

-Optimizing compiler

What is ampersand in C Language?

The ampersand '&' has many uses in the C++ language:

The single ampersand can be used to reference the pointer address of a pointer:

int* pointer;

int* anpointer;

anpointer = &pointer;

This example, although perhaps not valid, shows that the anpointer reference is now the same as the reference to the pointer memory address.

The single ampersand can also be used to reference an object in a function:

void function( int param1, int param2, int &reference );

If this function were to be called, and the reference object altered within the function, the actualy object that was passed into the function would be altered.

The double ampersand '&&' specifies that the left AND the right concepts must both be true before the whole statement is true. For example:

if( conceptA true )

{

conceptC = true;

}

Why is C plus plus such a robust programming language?

Borland's implementation of C++ was never regarded as the Bible of Computer Programming (whatever that means). If it were we'd probably still be using it today, but it was rendered obsolete in 1997 when Borland C++ Builder superseded it.

What is difference between constant in c plus plus and final in java?

The final keyword can be used to modify a class, method, or variable.

When used on a variable, it means that variable cannot be changed once set.
When used on a method, it means that no subclasses may override that method.

What is Runtime Error?

In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination (compare compile time). The term is also used as a short form when referring to a runtime library (without a space), a program or library of basic code that is used by a particular computer language to manage a program written in that language while it is running. A runtime environment is a virtual machine state which provides software services for processes or programs while a computer is running. It may pertain to the operating system itself, or the software that runs beneath it.

How many operators in c?

Quite a few. Some of them are:

, () [] & * . ->

+ ++ += - -- -=

* / % *= /= %=

! == <= >= < > !=

<< >> >>= <<=

& | ^ ~

&&

What are the disadvanteges of high level programming language?

Depends on the purpose of the program your creating. Generally speaking high level languages require far more system resources than low level languages. So if you were writing embedded code on a microcontroller, writing in Java would be a big no no as you'd barely be able to do anything whereas in C or assembler you could write a functional and useful program. (C is often used for faster development and high accuracy whereas assembler can be moulded to high performance low accuracy).

What is the importance of an array?

The primary use of an array is create a collection of anonymous variables of the same type.

Although we can name all our variables at compile time, we can only do so if we know precisely how many variables we require at compile time. Even then, if the number of variables is large enough, naming and referring to each one by name can be impractical; imagine naming a million integer variables individually!

Arrays allow us to refer to a collection of variables through a single name; the array name. Every variable in an array must be of the same type. The variables are known as "elements" and the elements must be stored contiguously (one after the other). The array name serves as a reference to the start address of the array and thus to the first element of the array. All other elements are anonymous.

For any given type T, the type T[n] is an array of n elements of type T, where n is a constant. The number of elements in an array is limited only by available memory, bearing in mind that memory must be allocated as a single contiguous block. Arrays can also be disk-based however the same principals apply to both disk-based and memory-based arrays.

Consider the following declaration:

int x[1000];

The name x refers to an array of 1000 integer elements. The amount of memory physically allocated to this array is 1000 * sizeof (int) bytes. If we suppose that sizeof (int) is 4 bytes, the amount of memory allocated will be exactly 4000 bytes. The compiler can work this out from the declaration alone.

The compiler can also work out the address of every element within the array using a zero-based index. We use the subscript operator to refer to individual elements by index:

x[10] = 42;

Here, we've assigned the value 42 to the 11th element (index 10). The compiler calculates the address of the 11th element using trivial pointer arithmetic:

sizeof (int) * 10 + x;

Note that x, &x and &x[0] all refer to the same memory address (the address of the 1st element).

Arrays may be fixed-length or variable-length. We use fixed-length arrays when we know exactly how many elements we need at compile time. Fixed-length arrays may be allocated statically (in the program's data segment), on the call stack or on the heap (the free store). Variable-length arrays can only be allocated on the heap.

To create an array on the heap we need to use a pointer variable to keep track of the start address:

void f (const int elements) {

int* p1 = malloc (1000 * sizeof (int)); // fixed-length array on the heap

int* p2 = malloc (elements * sizeof (int)); // variable-length array on the heap

// use arrays...

p1[10] = 42;

// ...

free (p2);

free (p1);

}

Note that we can use the array subscript operator with any pointer type except void*. This is because the compiler needs to know the length of the type being pointed at, but sizeof (void) is meaningless.

Whenever we pass arrays to functions we must always pass the length of the array through a separate argument. This is because an array implicitly converts to a pointer to the first element and we cannot determine how many elements are actually being referred to from the pointer alone:

void f (int a[], unsigned len) {

for (int i=0; i<len; ++i) printf ("%d\n", a[i]);

}

The only exceptions to this are null-terminated arrays or arrays that use some pre-determined value to mark the end of the array. Character arrays (strings) are a typical example:

void g (char* str) {

printf ("%s", str); // Note: str must be null-terminated!

}

Note that, by convention, we use char* when referring to a null-terminated string rather than char[]. The latter is conventionally used to denote a non-null terminated string in which case we must also pass the string's length:

void h (char str[], unsigned len) { for (int i=0; i<len; ++i) printf ("%c", str[i]);

}