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

Why is assembly language called a low level language?

x86 assembly language is crucial to be able to do any serious security or reverse engineering work. In addition, it allows one to write well optimized code. It also gives the opportunity to understand how things really work inside the computer, which is by itself very important if you want to become a competent programmer.

x86 assembly language is not very hard to learn. In fact, if you know basic math (The one that you learn in elementary school), you could learn it yourself.

I recorded an online video course for x86 assembly (paid) and exercises (Open source).

You can find it at the address xorpd dot net.

This course will teach you x86 assuming that you know nothing. It only assumes

that you know how to add numbers. (In base 10).

In the end of the course you will be able to write fully working x86 assembly

programs on the Fasm assembler over the Windows operation system.

xorpd.

What is a primitive campground?

Many "primitive" campgrounds are located in wilderness areas on federal or state land.

Generally, a "primitive" campground means one with few, little, or NO improvements.

Basically, a cleared patch of ground to pitch a small tent or lay down your sleeping bag.

Improvements are generally things like:

- running water, as opposed to a hand pump or well

- a toilet or an outhouse/privy

- electricity or lights

- buildings, cabins, shelters, ...

What is meant by arguments in c?

Arguments appear in functions and in function calls. Arguments passed to a function are known as actual arguments. The arguments used by the function are known as the formal arguments. In C, all arguments are passed by value, such that the formal argument is a copy of the actual argument.

How can I change the output font of a C program?

C++ doesn't understand the notion of a font. To work with fonts you will need a graphics library. The library will provide the methods required to change font sizes.

Example of predefined function?

function callMe (fx_params) {

alert(fx_params);

}

callMe('Alert Loaded from a JavaScript function');

This would be in a javascript page, or in a JS Script tag..

- Caleb

Convina Web Design and Hosting

What is purpose of AVL tree?

AVL TreesIn computer science, an AVL tree is the first-invented self-balancing binary search tree. In an AVL tree the heights of the two child subtrees of any node differ by at most one, therefore it is also known as height-balanced. Lookup, insertion, and deletion are all O(log n) in both the average and worst cases. Additions and deletions may require the tree to be rebalanced by one or more tree rotations.

The AVL tree is named after its two inventors, G.M. Adelson-Velsky and E.M. Landis, who published it in their 1962 paper "An algorithm for the organization of information."

The balance factor of a node is the height of its right subtree minus the height of its left subtree. A node with balance factor 1, 0, or -1 is considered balanced. A node with any other balance factor is considered unbalanced and requires rebalancing the tree. The balance factor is either stored directly at each node or computed from the heights of the subtrees.

2 Write a program in java to find factorial of a number?

import java.math.BigInteger;

public class Factorial {

public static void main(String[] args) {

BigInteger n = BigInteger.ONE;

for (int i=1; i<=20; i++) {

n = n.multiply(BigInteger.valueOf(i));

System.out.println(i + "! = " + n);

}

How do you write a C program to check whether a number is prime or not and to find the nth prime number?

int number;

int i=2;

while (i<number)

{

if(number%i==0)

{

printf("Not a prime no.");

break;

}

else

printf("number entered is prime");

getch();

}

What is enum in c?

Enumerations are a method of grouping constant values. For example:

enum suits { clubs, diamonds, spades, hearts };

By default, the first constant is assigned the value 0 and all subsequent values increment by 1. However, you can assign any value to any constant -- the automatic increments will continue from that point.

enum suits { clubs = 1, diamonds, spades, hearts };

You can also assign the same value to multiple constants.

enum suits { clubs = 1, diamonds, spades = 1, hearts };

By grouping constants within enumerations your code becomes more secure because you cannot pass constant literals into functions that expect an enumeration. Consider the following:

void print_suit(unsigned id)

{

switch (id)

{

case (0): std:cout << "Clubs"; break;

case (1): std:cout << "Diamonds"; break;

case (2): std:cout << "Spades"; break;

case (3): std:cout << "Hearts"; break;

default: std::cout << "Invalid";

}

}

In the above example there is nothing to prevent the caller from passing an invalid value, such as 42, which the function caters for with a default case. However, by passing an enum instead, invalid values are completely eliminated:

void print_suit(suits suit)

{

switch (suit)

{

case (clubs): std:cout << "Clubs"; break;

case (diamonds): std:cout << "Diamonds"; break;

case (spades): std:cout << "Spades"; break;

case (hearts): std:cout << "Hearts";

}

}

Parameterized constructor in c plus plus?

Every class requires at least one constructor, the copy constructor. It is implied if not declared. If no constructors are declared, a default constructor is also implied. Every class also requires a destructor, which is also implied if not declared.

The purpose of constructors is to construct the object (obviously) but by defining your own you can control how the object is constructed, and how member variables are initialised. By overloading constructors, you allow instances of your object to be constructed in several different ways.

The copy constructor's default implementation performs a member-wise copy (a shallow-copy) of all the class members. If your class includes pointers, you will invariably need to provide your own copy constructor to ensure that memory is deep-copied. That is, you'll want to copy the memory being pointed at, not the pointers themselves (otherwise all copies end up pointing to the same memory, which could spell disaster when one of those instances is destroyed).

The destructor allows you to tear-down your class in a controlled manner, including cleaning up any memory allocated to it. If your class includes pointers to allocated memory, you must remember to delete those pointers during destruction. The destructor is your last-chance to do so before the memory "leaks". The implied destructor will not do this for you -- you must implement one yourself.

class foo

{

public:

foo(){} // Default constructor.

foo(const foo & f){} // Copy constructor.

~foo(){} // Destructor.

};

Swap function in c plus language?

#include<iostream>

void swap(int* x, int* y)

{

int tmp = *x; *x=*y; *y=tmp;

}

int main()

{

int a=2, b=4;

std::cout<<"a="<<a<<", b="<<b<<std::endl;

swap(&a, &b);

std::cout<<"a="<<a<<", b="<<b<<std::endl;

}

How is a c plus plus program stored in the memory?

C++ programs are not stored in memory (RAM) they are stored on mass storage devices (usually disk drives). When compiled, they produce machine code programs which contain machine instructions and their operands. These are also stored on mass storage devices, but when loaded into memory the machine instructions are executed by the CPU.

What is the difference between a binary tree and a complete binary tree?

Let's start with graphs. A graph is a collection of nodes and edges. If you drew a bunch of dots on paper and drew lines between them arbitrarily, you'd have drawn a graph.

A directed acyclic graph is a graph with some restrictions: all the edges are directed (point from one node to another, but not both ways) and the edges don't form cycles (you can't go around in circles forever).

A tree, in turn, is a directed acyclic graph with the condition that every node is accessible from a single root. This means that every node has a "parent" node and 0 or more "child" nodes, except for the root node which has no parent.

A binary tree is a tree with one more restriction: no node may have more than 2 children.

More specific than binary trees are balanced binary trees, and more specific than that, heaps.

A binary tree can be empty ..whereas the general tree cannot be empty

What is binary search and linear search in data structure?

A Binary Search is a technique for quickly locating an item in a sequential list.

A Sequential Search is a procedure for searching a table that consists of starting at some table position (usually the beginning) and comparing the file-record key in hand with each table-record key, one at a time, until either a match is found or all sequential positions have been searched.

Importance of functions in c?

Based on execution

1. Iterative Function

2. Recursive Function

Based on Argument and return value

1. No argument No return value

2. With argument Without return value

3. With out argument without return value

4. With argument With return value

What are the six stages that typical c programs go through to be executed?

First of all the source code is get compiled and the object code is returned i.e.binary code(machine language).Then the Linker, a computer program that takes one or more objects generated by a compiler and combines them into a single executable program. Now when the program is executed then the .exe file is first loaded into the memory and then executed by the processor.

In short the steps are:

1.Compilation

2.Linking

3.Loading

4.execution

Difference between portability and platform independent?

Platform independence refers to the fact that java compiled code (byte code) can execute on any operating system. A programme is written in a language that can be understood by humans. It could contain words, phrases, or other information that the system doesn't understand.... The Java Byte Code is the intermediate representation in Java.

To learn more about data science please visit- Learnbay.co

What are the features of static data members in c?

A non-static member function has a hidden argument called the this-pointer which points to the data of the specific instance of the class. Static member functions can be called without reference to a specific instance of the class so it is completely what instance if any you mean. You do this by treating them as functions in a namespace with the same name as your class.

Here's an illustrative example:

class CPerson

{ private:

int m_Age; static int m_NumPeople = 0;

public: void SetAge( int Age ){ this->m_Age = Age }; // Correct, if you omit "this->" the compiler will still infer its existance.

CPerson( void ){ m_NumPeople++ };

~CPerson( void ){ m_NumPeople-- };

static int GetAge( void ){ return this->m_Age }; // Wrong, this-> is ambiguous for static functions.

static int GetPeople( void ){ return m_NumPeople}; // Correct, people count is static.

};

There is only one integer m_NumPeople, it behaves like a global variable but the compiler will only let member functions access it since it is private.

m_NumPeople is created with a default value of zero before you even instantiate your first CPerson. As you instantiate CPersons the constructor is called when each instance is created and the instance counter named m_NumPeople is incremented. As these instances are destroyed the destructor decrements m_NumPeople.

Since GetPeople is static you can call it without having access to any instance of the class like so: CPerson::GetPeople();

The compiler has no mechanism to infer which object you called the static function on or even guarantee that the object has ever been instantiated, therefor CPerson::GetAge() is ambiguous and the compiler spits out an error. CPerson::SetAge( 42) is now allowed either. SetAge needs a this-pointer to find the correct instance of m_Age to set.

When you have some instance of the object you use the . operator or -> operator like so: CPerson Nicholas( ); Nicholas.SetAge( 42 ); Now the compiler can uniquely identify the CPerson in question as Nicholas. It will pass the pointer &Nicholas to the SetAge function. Calling conventions vary, but if you're using microsofts visual studio compiler and compiling 32-bit code it will pass the this pointer in the ECX register and the function parameters will be pushed onto the stack in reverse order(but in this case there's only one).

Is c language is heterogeneous?

Programming languages cannot be 'portable', but programs written in C might be portable, if they follow the strictest standards and do not use platform-specific features or functions.

What is the difference between struct in c and c plus plus?

In C, a struct is simply a type that can hold several sub-objects.

In C++, struct is almost the same as "class". It can have member functions, parent structs and classes, etc. The only difference between struct and class is that the members of class are by default private, while the members of struct are by default public. Thus, a standard C struct is also a good C++ struct - simply one that has no member functions and no parents.

Which are the software programming languages?

There are many programming languages all suitable for many purposes. (Except Java, that one is lame)

The largest list of programming languages I could find is at

http://en.wikipedia.org/wiki/Alphabetical_list_of_programming_languages

A programming language is a medium to solve any problem step by step.

Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.Programming or coding is a language that is used by operating systems to perform the task.Basically there are two different programming approaches; procedure oriented and object oriented. The procedure oriented programming (POP) approach focuses on creating and ordering procedures or a block of code keeping in mind to accomplish a specific job. The key features of this kind of approach are: use of procedures, sequencing of procedures and sharing global data.However, in case of the object oriented programming (OOP) approach the focus is totally towards identifying objects or data and not on creative activities. Now a days most of the high level programming languages such as Java, C#, C++, and Visual Basic are based on object oriented approach.

What are the advantages of using an assembly programming language in comparison to using an Object Oriented programming language?

The main strength is that it gives complete control over the machine at the lowest possible level. The main weakness is that everything must be encoded in terms the machine can understand. For instance, the otherwise simple operation of x = y + z requires that we move the values stored at the addresses identified by y and z into the appropriate CPU user registers, then invoke the appropriate ADD instruction, then move the accumulator register value into the address identified by x. That's a lot of work for an otherwise simple operation.

How should you Swap 2 numbers in a single line?

Swapping two values in a single statement is made possible through a series of three XOR/assign operations, alternating the operands.


Consider the following declarations:


int x = 0;

int y = 1;


The following statement will swap the values of x and y:


x ^= y ^= x ^= y; // swap



The same statement implemented as a function:


void swap(int &x, int &y){ x ^= y ^= x ^= y; }





What is the recursive solution in data structure?

You cannot have recursion within a data structure:

struct foo {

int x;

foo y; // compiler error

};

This has to fail; there is no end point to the recursion. If a foo is member of a foo, then the member foo also requires a member foo, and so on to infinity...

If a structure needs to refer to another instance of itself, we can use a member pointer:

struct foo {

int x;

foo* y; // ok

};

A pointer works because all pointers are the same length regardless of the pointer's type (the type being referred to).

Using member pointers like this is fundamental to many data structures, such as linked lists:

struct node {

int data;

node* prev; // previous node in the sequence (may be NULL)

node* next; // next node in the sequence (may be NULL)

};