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 storage allocation and scope of global extern static local and register variables?

AnswerLocal Variables are stored in Stack. Register variables are stored in Register. Global variables are stored in data segment. The memory created dynamically are stored in Heap And the C program instructions get stored in code segment and the extern variables also stored in data segment.

Nooo Nooo

Static variable will be stored in .BSS segment... (Block Started By Symbol)

Where string arrays belong in a C program?

There is no data type string in C. String is handled as an array of characters. To identify the end of the string, a null character is put. This is called a null terminated character array. So array of strings will be a double dimensioned array of chars. It is implemented as an array of pointers, each pointer pointing to an array of chars.

Maximum static memory size in c plus plus?

The maximum size of an array in C++ is the same as the maximum number that can be represented by an int (usually 2,147,483,647 elements, or just over 2 billion). An int is defined as being dependent on a CPU's architecture, so the 2 billion number is based on 32-bit compilation. Some 64-bit processors also compile to a 32-bit int, and would be limited to just over 2 billion elements.

Available memory is also a consideration on the maximum size of an array. The larger the elements, the fewer elements you can achieve. This is unlikely to be a problem on 64-bit systems, but on 32-bit systems it could be.

What does BASIC as in the programming language stand for?

Beginners All-purpose Symbolic Instruction Code > B.A.S.I.C. > Basic.

John Kemeny and Thomas Kurtz developed the first version at Dartmouth University in 1964. It was originally created to allow non technical people to run a computer because, at that time, you couldn't operate a computer without programming it first. Basic was developed to give a more simple programming structure that was close to plain English so that anyone could use a computer. It has come a very long way since then becoming a very robust language.

What are the arithmetic and logical operator?

AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.




AND, OR, and NOT are the most common ones. There are others, too, such as XOR.


Writea c program to print the day for an input of date month and year?

#include<iostream>

#include<string>

#include<ctime>

using namespace std;

std::tm input_date()

{

while (true)

{

cout << "Enter date (dd/mm/yyyy): ";

string input;

getline (cin, input);

size_t d, m, y;

int n = sscanf (input.c_str(), "%u/%u/%u", &d, &m, &y);

if (n!=3)

cout << input << " is not a valid date." << endl;

else

{

tm date;

memset (&date, 0, sizeof(tm));

date.tm_isdst = -1;

date.tm_mday = d;

date.tm_mon = m-1;

date.tm_year = y-1900;

return date;

}

}

}

int main()

{

tm date = input_date();

time_t tt = mktime (&date);

date = *localtime(&tt);

switch (date.tm_wday)

{

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

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

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

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

case (4): std::cout << "Thursday"; break;

case (5): std::cout << "Friday"; break;

case (6): std::cout << "Saturday"; break;

}

std::cout << std::endl;

}

Write a c program to arrange the digits of a number in ascending order?

#include

#include

void main()

{

int n ,i,j,temp,a[12]; //in a[] specify some number .

printf("Enter the no of inputs:");

scanf("%d", &n);

printf("Enter %d integer numbers :", n);

for(i=0;i

{

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

}

for (i=0;i

for(j=i+1;j

{

if(a[i]>a[j])

{

temp=a[j];

a[j]=a[i];

a[i]=temp;

}

}

printf("THE %d NUMBERS SORTED IN ASCENDING ORDER ARE :\n", n);

for(i=0;i

{

printf("%d ",a[i]);

}

getch();

}

Here is another version of the program. While the previous one is obviously simpler, this one is a good program to master the basics of pointer and array problems which might plague them at the beginning.

#include

#include

int a[100],i,j,k,n;

void sort(int *a,int n);

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

main()

{

printf("How many numbers? ");

scanf("%d",&n);

printf("Enter the %d numbers separated from each other by a blank space: \n\n",n);

for (i=0;i

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

sort(a,n);

printf("\nThe numbers in descending order is: \n");

for (k=0;k

printf("\n%d",a[k]);

printf("\n\n");

}

void sort(int *a,int n)

{

int p=n-1;

while (p>=0)

{

for(i=0;i<=(p-1);++i)

{

if (a[i]<=a[i+1])

swap(&a[i],&a[i+1]);

else

continue;

}

--p;

}

}

void swap(int *x,int *y)

{

int t;

t=*x;

*x=*y;

*y=t;

}

How do you convert binary numbers to hexadecimal notation?

Each hexadecimal digit represent four binary bits. Using the table... 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1110 ... replace each hexadecimal digit with its correspnding binary digits. As an example, 37AB16 is 00110111101010112.

List and explain bitwise operators in C language?

void main()

{

unsigned int word1 = 077u, word2 = 0150u, word3 = 0210u;

printf ("%o ", word1 & word2);

printf ("%o ", word1 & word1);

printf ("%o ", word1 & word2 & word3);

printf ("%o\n", word1 & 1);

getch();

}

What are proxy classes in c plus plus?

A proxy is defined as any entity that acts on behalf of another entity. For instance, a proxy server is a server that you use to make network calls on your behalf. The proxy server effectively hides your identity from the network because the network only sees the proxy server.

A proxy class is a similar concept -- it is simply a class that acts on behalf of another class. Proxy classes are typically used to simplify the interface to a larger, more complex object.

Note that this is not the same as deriving one object from another. Although you can achieve the same sort of thing with derivation, a proxy class contains a member pointer to the class it acts upon, it does not derive from it. Thus it is free to override the class behaviour, but does not inherit any of its underlying complexity.

"Wrapper" classes are a form of proxy. They contain a class member pointer but they expose a limited or simplified interface to that class member, making more complex calls to that class on your behalf.

Proxy classes can also be used as a reference counting mechanism. Rather than having multiple copies of the same complex object, you can have several lightweight proxy classes all pointing to a single instance of an object, each of which acts on its behalf. Copying lightweight objects does not copy the original object, thus reducing the memory footprint of that object, and when all the lightweight classes finally fall from scope, the original object also falls from scope.

C program to create symbol table?

Aim:
To write a C program to implement Symbol Table system software lab CS1207
Algorithm:
Start the program for performing insert, display, delete, search and modify option in symbol table
Define the structure of the Symbol Table
Enter the choice for performing the operations in the symbol Table
If the entered choice is 1, search the symbol table for the symbol to be inserted. If the symbol is already present, it displays "Duplicate Symbol". Else, insert the symbol and the corresponding address in the symbol table.
If the entered choice is 2, the symbols present in the symbol table are displayed.
If the entered choice is 3, the symbol to be deleted is searched in the symbol table. If it is not found in the symbol table it displays "Label Not found". Else, the symbol is deleted.
If the entered choice is 5, the symbol to be modified is searched in the symbol table. The label or address or both can be modified.

Source Code program in c implement symbol table
# include
# include
# include
# include
# define null 0
int size=0;
void insert();
void del();
int search(char lab[]);
void modify();
void display();
struct symbtab
{
char label[10];
int addr;
struct symtab *next;
};
struct symbtab *first,*last;
void main()
{
int op;
int y;
char la[10];
clrscr();
do
{
printf("\nSYMBOL TABLE IMPLEMENTATION\n");
printf("1. INSERT\n");
printf("2. DISPLAY\n");
printf("3. DELETE\n");
printf("4. SEARCH\n");
printf("5. MODIFY\n");
printf("6. END\n");
printf("Enter your option : ");
scanf("%d",&op);
switch(op)
{
case 1:
insert();
display();
break;
case 2:
display();
break;
case 3:
del();
display();
break;
case 4:
printf("Enter the label to be searched : ");
scanf("%s",la);
y=search(la);
if(y==1)
{
printf("The label is already in the symbol Table");
}
else
{
printf("The label is not found in the symbol table");
}
break;
case 5:
modify();
display();
break;
case 6:
break;
}
}
while(op<6);
getch();
}
void insert()
{
int n;
char l[10];
printf("Enter the label : ");
scanf("%s",l);
n=search(l);
if(n==1)
{
printf("The label already exists. Duplicate cant be inserted\n");
}
else
{
struct symbtab *p;
p=malloc(sizeof(struct symbtab));
strcpy(p->label,l);
printf("Enter the address : ");
scanf("%d",&p->addr);
p->next=null;
if(size==0)
{
first=p;
last=p;
}
else
{
last->next=p;
last=p;
}
size++;
}
}
void display()
{
int i;
struct symbtab *p;
p=first;
printf("LABEL\tADDRESS\n");
for(i=0;i{
printf("%s\t%d\n",p->label,p->addr);
p=p->next;
}
}
int search(char lab[])
{
int i,flag=0;
struct symbtab *p;
p=first;
for(i=0;i{
if(strcmp(p->label,lab)==0)
{
flag=1;
}
p=p->next;
}
return flag;
}
void modify()
{
char l[10],nl[10];
int add, choice, i, s;
struct symbtab *p;
p=first;
printf("What do you want to modify?\n");
printf("1. Only the label\n");
printf("2. Only the address of a particular label\n");
printf("3. Both the label and address\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the old label\n");
scanf("%s",l);
printf("Enter the new label\n");
scanf("%s",nl);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i{
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
}
p=p->next;
}
}
break;
case 2:
printf("Enter the label whose address is to modified\n");
scanf("%s",l);
printf("Enter the new address\n");
scanf("%d",&add);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i{
if(strcmp(p->label,l)==0)
{
p->addr=add;
}
p=p->next;
}
}
break;
case 3:
printf("Enter the old label : ");
scanf("%s",l);
printf("Enter the new label : ");
scanf("%s",nl);
printf("Enter the new address : ");
scanf("%d",&add);
s=search(l);
if(s==0)
{
printf("NO such label");
}
else
{
for(i=0;i{
if(strcmp(p->label,l)==0)
{
strcpy(p->label,nl);
p->addr=add;
}
p=p->next;
}
}
break;
}
}
void del()
{
int a;
char l[10];
struct symbtab *p,*q;
p=first;
printf("Enter the label to be deleted\n");
scanf("%s",l);
a=search(l);
if(a==0)
{
printf("Label not found\n");
}
else
{
if(strcmp(first->label,l)==0)
{
first=first->next;
}
else if(strcmp(last->label,l)==0)
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
}
p->next=null;
last=p;
}
else
{
q=p->next;
while(strcmp(q->label,l)!=0)
{
p=p->next;
q=q->next;
}
p->next=q->next;
}
size--;
}
}

What are Principles of object oriented programming language?

Java is an object oriented programming language. The main concepts used in Java are:

Class

Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.

Object

A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.

Instance

One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.

Method

An object's abilities. In language, methods (sometimes referred to as "functions") are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.

Message passing

"The process by which an object sends data to another object or asks the other object to invoke a method." Also known to some programming languages as interfacing. For example, the object called Breeder may tell the Lassie object to sit by passing a "sit" message which invokes Lassie's "sit" method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java, code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.

Inheritance

"Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.

For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.

Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog.

Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well.

Abstraction

Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.

For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.

Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.

Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.

For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface - those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.

Polymorphism

Polymorphism allows the programmer to treat derived class members just like their parent class' members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as "+", to perform several different functions depending on the implementation. The "+" operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the addition operator, "+", to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.

Decoupling

Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other. However, in practice decoupling often involves trade-offs with regard to which patterns of change to favor. The science of measuring these trade-offs in respect to actual change in an objective way is still in its infancy.

Note: Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance.

What are the limitation of object oriented programming language?

  • Performance (since the generated code is much more than when working procedural)
  • Memory (more memory is needed to store code and data)

What are the functions of a utility program?

functions of utility program is to perform specific tasks related to the management of computer functions,resources or files as password protection,memory management,virus protection and file compression
This utility reads all V3 MMS output files, print out the header, partial sub-header and a value from all fields in the dataset.

What is the difference between mirco and macro?

macro-The climate of a large geographic area.

micro- is a local atmospheric zone where the climate differs from the surrounding area

How does loop work?

In programming, a loop works by conditionally jumping to the start of the loop and repeating the instructions. If the condition evaluates false, execution continues to the next instruction, thus breaking out of the loop. We can also break out of a loop from within the body of the loop itself using another conditional jump which jumps out of the loop. If we jump backwards out of a loop we effectively create an intertwined loop, known as spaghetti code which is difficult to read and maintain. Structured loops help make it easier to digest the logic. In C, a jump is achieved using a goto and a label. However, structured loops using for, while and do-while statements make loops much easier to read and maintain.

Can you specify variable field width in scanf format string?

Answer

You can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:

int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value);

The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.

Answer

If you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:

printf("%*d", width, num);

That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.

What is a general loader scheme?

Loading schemes: 1.Absolute loader. 2.Relocating loader. 3.Direct linking loader. 4.Dynamic Loading. 5.Dynamic linking.

(1 )Absolute loader: The task of an absolute loader is virtually trivial.The loader simply accepts machine language code and places it into main memory specified by the assembler.

(2) Relocating loader: The task of relocating loader is to avoid reassembling of of all subroutines when a subroutine is changed and to perform tasks of allocation and linking for programmer.

(3) Dynamic loading: In order to overlay structure to work it is necessary for the module loader to load the various procedures as they are needed.There are many binders capable of processing and allocating overlay structure.the portion of the laoder that actually intercepts calls and loads necessary procedure is called overlay supervisor of simplly flipper.this overall scheme is called dynamic loading or load on call.

(4) Dynamic linking: This is mechanism by which loading and linking of external references are postponed until execution time.This was made to sort out disadvantage of previous loading schemes like subroutine is referenced and never executed

What is function overloading?

FUNCTION OVERLOADING:

- when we define two functions with same name,in same class(may be) distinguished by their signatures

- resolved at compile time

- same method bt different parameters in each of them

FUNCTION OVERRIDING:

- when we redifine a function which is already defined in parent class

- resolved at run time

- changing the existing method

What is similarity between a union and enumeration?

Nothing, only the syntax (very little).

Eg.:

struct {

int foo;

double bar;

} strtest;

enum {

monday=0,

tuesday=1, ...

} enumtest;

What is primitive style?

The definition of primitive characters is characters that are defining members of a clade that people believe rose early in the evolution of the group. They can be the characters of a large group who share being early members.