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 is the decimal conversion of the binary number 1111 1111 and 10101010?

Starting at the right with the "ones", the value of each successive place doubles. So: 1, 2, 4, 8, 16 etc. The value of the place is either 0 x that number or 1 x that number. You figure out the value of each place and add them up.

So you have:

0 x 1 =0

0 x 2 =0

1 x 4 =4

1 x 8 =8

1 x 16 =16

0 x 32 =0

1 x 64 =64

1 x 128 =128

1 x 256 =256

0 x 512 =0

0 x 1024 =0

1 x 2048 =2048

0 x 4096 =0

1 x 8192=8192

_______+_____

10716

What is the worst case and best case of bubble sort?

There is no worst case for merge sort. Each sort takes the same amount of steps, so the worst case is equal to the average case and best case. In each case it has a complexity of O( N * log(N) ).

What are the sum of the first 100 integers using the do while loop and display the result?

public class TestBB {

/**

* @param args

*/

public static void main(String[] args) {

int sum = 0;

int i = 0;

do {

sum = sum + i;

i++;

} while (i <= 100);

System.out.println("Total of 100 numbers is: " + sum);

}

}

What is sixth generation in programming language?

There is no such thing. Until the introduction of third generation hardware, languages were never actually classified by generation. They were either low-level symbolic languages or high-level abstract languages and that hasn't changed to this day. The terms 3GL, 4GL and 5GL are nothing more than buzzwords adopted by the software industry for marketing purposes but they have no practical meaning as no such specification exists to define them.

Historically, the term 3GL arose after the introduction of third generation hardware. Thus all previous high-level languages became known as 2GL while assembler became 1GL. But it was all done reflexively as a result of market hype. Since then, we've seen 4GL and 5GL applied to programming languages but no-one can actually agree on what these terms really mean. They are marketing buzzwords, nothing more.

In some cases, 4GL and 5GL is nothing more than 3GL with some enhancement. In others, 4GL and 5GL are a completely new form of language altogether. Ultimately, comparing two 5GL languages is like comparing chalk with cheese. The term tells us nothing about the actual software.

Some attempts have been made to clearly define the difference between 4GL and 5GL. To some, a 4GL is a domain-specific language (DSL) while to others it is a subset of DSL. Meanwhile 5GL is generally regarded as being intended for artificial intelligence applications. However, just as with 1GL, these are merely reflexive definitions attempting to make sense of the meaningless. Unless the industry as a whole can formally agree upon what 6GL means, then it will be just as meaningless. All we can say for sure is that 6GL will follow 5GL. But that doesn't mean it is any better than 5GL, only that it is newer in some way.

How do you find a factorial using Unix?

perl -e 'sub f { my $fu = shift; return 1 if $fu == 1; return f($fu - 1) * $fu; } print f(5), "\n";'

just paste that in to a command prompt, change the print f(5) to print f(6) or whatever you want.

What is the major difference between c and c plus plus?

C is an imperative (procedural), structured paradigm language whereas C++ is multi-paradigm: procedural, functional, object-oriented and generic. Both are high-level, abstract languages. While C's design provides constructs that map efficiently to machine code instructions, C++ is more abstract, relying heavily upon object-oriented principals. However, both are equally capable of producing highly-efficient machine code programs. C++ derives almost directly from C thus everything you can do in C you can do in C++ with relatively minor alterations to the source. C++ was originally called C with Classes and that pretty much sums up the main difference between the two languages. However, there are many subtle differences.

One key difference between C and C++ is in the struct data type. In C, a struct can only contain public data members (with no methods). In C++, a struct is similar to a class, combining data and the methods that operate upon that data into a single entity (an object). The only difference between a C++ struct and a C++ class is that class members are private by default whereas struct members are public by default.

Another key difference is that because C++ is object oriented, there is much less reliance upon the programmer to manage memory. Each object takes care of its own memory allocations (including embedded objects), thus the programmer simply creates and destroys objects as needed. Thus C++ is much easier to work with, especially with regards to highly-complex hierarchical structures, but is every bit as efficient as C.

Both languages are highly popular and there are few architectures that do not implement suitable compilers for both. Thus they are both highly portable. However, the object oriented approach to programming gives C++ a major advantage over C in terms of code re-usability, scalability and robustness.

What is mean by selection sort?

Selection sort works by looking for the largest value in a set and swapping it with the last value. The last value can now be ignored since it is now in place. The process repeats with the remainder of the set. After repeated passes, the remainder of the set will have only one item, the smallest value, at which point all the values will be in sorted order.

The algorithm is similar to that of bubblesort, but is generally more efficient because there can only be one swap at most for each iteration of the algorithm. With bubble sort, there may be multiple swaps per iteration. However, while the number of comparisons is the same for both algorithms, bubblesort can be optimised to minimise the number of iterations required and thus minimise the number of comparisons. Nevertheless, swapping is a more expensive operation than comparing, thus selection sort is generally faster.

Neither algorithm is suitable for sorting large sets of data.

What is the formula to find sum of n even numbers?

Sum = n/2[2Xa1+(n-1)d] where n is last number, a1 is the first number & d is the common difference between the numbers, here d=2 for the even /odd numbers. Sum = n/2 [2Xa1+(n-1)2]

Why should all of the elements in an array have the same data type?

Yes all of the elements in array must be the same type.

Because when you define an array you specify the type of data it will hold.

Examples in C:

int IntArray[10]; // an array of 10 integers

double FloatArray[20]; // array of 20 double floating point numbers

Is it true or false that a dynamically linked list can be accessed both sequentially and randomly?

No. Linked lists require traversal, and are therefore accessed sequentially. For random access you need an array. An array of pointers to the data in your list would do, but you will incur an overhead in creating the array on top of the list.

Is void a data type in c?

what is void data type

Void is an empty data type normally used as a return type in C/C++, C#, Java functions/methods to declare that no value will be return by the function.

The another use of void is to declare the pointer in C/C++ whe It is not sure that what data type will be addressed by the pointer.

eg:

void *p;

Here p can hold the address of int or float or char or long int or double.

Can you use pointers in c language?

Pointers in C allow you to transfer references data around without transferring the data itself.

Think of it like a parcel. Instead of sending the entire package which might cost a lot in postage, you send a slip of paper with the location of the package and the other person goes and collects it from that location. The "cost" of sending the slip of paper is comparable to the memory and time "cost" of transferring data in a program.

To take the analogy further, you can send slips of paper to lots of people who can all go and reference the same package, which saves you making copies of the package which would take up more space (memory).

Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.

What are the advantages of functionalism?

Functionalism is defined as the theory that all aspects of a society serve a function and are necessary for the survival of that society, the theory that mental states can be sufficiently defined by their cause, their effect on other mental states, and their effect on behavior. The advantages are a reassurance of our values, boundary formation, social change, and social affirmation.

Why do more programmers prefer to write programs using high level language than low level language?

A high level language like Java is easier for programmers (Us) to understand. The machine language will be in binary & byte codes which is very difficult for the normal man to decipher and understand. Hence we prefer writing the code in HLL and then have a compiler or interpreter convert it into machine language for the machine to understand.

When should a for loop be used instead of a while loop?

The golden rule in iteration: everything done with a for loop can be done with a while loop, BUT not all while loops can be implemented with a for loop. for-loops are just a short-cut way for writing a while loop, while an initialization statement, control statement (when to stop), and a iteration statement (what to do with the controlling factor after each iteration). = Examples of for-loops = The most basic use for using for-loops is to do something a set number of times: for(int k = 0; k < 10; k++); // this loops runs for 10 times another less common use of the for-loop is traversing raw listNodes, since it does contain an initialization(finding the first node), control (as long as there is a next node), and a iteration statement (get my next node). i.e.: for(ListNode temp = startingNode; temp != null; temp = temp.getNext); // this traverses the entire ListNode list and stops when it has exhausted the list = How to implement for-loops using while loop = Basically for loops are just short hand for while loops, any for loop can be converted from: for([initialize]; [control statement]; [iteration]); to [initialize]; while([control statement]) { //Do something [iteration]; } These two does the exact same thing. = For When Only while Loop can be used = while-loops are used when the exiting condition has nothing to do with the number of loops or a controll variable, maybe you just want to keep prompting the user for an input until the given input is valid, like the following example which demands a positive number: int x = [grab input]; while(x < 0) { // Do code

x = [grab input];

} It is true that, when used as intended, a for loop cannot do everything a while loop can, however, in reality, for loops are just as versatile. For example, the above while loop can easily be rewritten to be a for loop as so:

for(int x = [grab input]; x < 0; x = [grab input]){

// Do Code

}

The above for loop behaves exactly like the while loop in the previous heading. A better example of a while loop that should not be a for loop might be:

while(true){

// Do some processing

// Check some condition. If condition is met, break out of loop.

// Do some more processing.

}

Here, the checking of the condition comes in the middle of the processing for the while loop, whereas the condition checked in a for loop is always done at the beginning of the loop. Also, the "iteration" statement is non-existant and is a factor of processing done somewhere else in the while loop. Finally, there was no initialization for this while loop. However, this while loop can still be written as a for loop:

for(;true;){

// Do some processing

// Check some condition. If condition is met, break out of loop.

// Do some more processing.

}

As you can see, a for loop is exactly like a while loop if you leave out the initialization and iteration sections (you still needs the semicolons, to signify those parts of the for loop are still there, they just do nothing). However, it is clear that when you do not need the extra portions of the for loop, why not just use a while loop?

The basic for loop was extended in Java 5 to make iterating over arrays and other collections more convenient. See this website for further explanation:

(http://www.leepoint.net/notes-java/flow/loops/foreach.html)

Java programming to check a digit number is palindrome or not?

import java.io.*;

public class chuva

{

public static void main(String[] args) throws Exception

{

BufferedReader x = new BufferedReader(new InputStreamReader(System.in));

int rem, quo, rev=0;

System.out.println("Enter a number: ");

int a = Integer.parseInt(x.readLine());

int b=a;

for(int ctr=0; ctr<=a; ctr++)

{

rem = a%10;

a = a/10;

rev = rev*10 +rem;

ctr=0;

}

System.out.println(+rev);

if(b==rev)

System.out.println("Palindrome");

else

System.out.println("Not Palindrome");

}

}

What is the difference between a programming language and an Application Programming Interface?

By what I think you asked yes but I can't give you a definite answer because your question does not make sense.

By what I can gather I think you accidently put that is after language.

Application-oriented languages are specialized languages which may be specified and implemented based on general-purpose languages and their implementations. The model used to introduce the specialized languages is based on translation. A simple model supports modifications and extensions of the general language only. An alternative model has an initial phase for defining a semantic basis for the specialized language in the form of a set of abstractions to model the concepts and notions of the application area. The use of specialized languages can be seen as an abstraction process, where several levels of languages (or language parts) are defined.

How do you get a recursive pattern?

A recursive pattern is a pattern that goes like this 2,4,6,8 and on. A pattern rule which is used to find the next term.

What is storage qualifiers in c?

A C++ qualifier is a keyword that contains semantic information related to a type. In other words, they are used to qualify a type.

The C++ qualifiers are const, mutable, restrict and volatile. Qualifiers do not alter the type's storage capacity nor how that storage is interpreted in any way.

The const qualifier is used to qualify that a type cannot be modified once it is initialised. As such, constants must be initialised at the point of instantiation, like so:

const int meaning_of_life = 42;

The const qualifier can also be used to qualify function arguments, like so:

void foo(const int x) { ... }

In this case, x is instantiated and initialised whenever the function is called.

The const qualifier can also be used with class instance methods (non-static member functions):

void foo::method() const { ... }

In this case, the const qualifier applies to the hidden this pointer, and thus ensures that the instance's non-mutable member attributes cannot be modified. Constant member methods may only access other other constant member methods of the same instance.

The mutable qualifier applies to class instance member data only. Data that is qualified as mutable may be modified by any method, including constant methods. You will typically use this feature for internal class data that does not alter the outward appearance of an object in any way. For instance, you might use internal caches or counters that do not alter the outward appearance of an object. If these members were not qualified as mutable, you wouldn't be able to modify them from within any constant methods. Note that the compiler uses a bitwise constant check to ensure all members remain unchanged within a constant method. The mutable keyword simply excludes the specified members from this check.

The restrict qualifier is not strictly a qualifier as it is not part of the C++ standard (it was introduced in C99) but some compilers support it. The restrict qualifier applies to pointers and references and merely provides a promise to the compiler that the object being referenced will only be access through the restricted reference or through copies of that reference.

The volatile qualifier denotes that a memory location may be modified by hardware or by external processes.