Is it every c program must have atleast one user defined function?
Yes, the minimum is the following:
int main (void) { return 0; }
How do you use union in embedded system C programming?
All members of a union are assigned the same memory address. As such, assigning to any member of a union changes the value of all members in that union.
The total number of bytes allocated to a union is equal to the length of the largest member of that union. Where the members differ in length, assigning to a member will completely overwrite all the smaller members but will only partially overwrite any larger members.
After assigning a value to a union member, that member is said to be "active". The active member remains active until a value is assigned to another member. However, a union does not keep track of which member is currently active; the onus is entirely upon the programmer to ensure the correct member is accessed.
In some cases, keeping track of the active member is not necessary. For instance, consider the following union:
union u {
int i;
char c[sizeof(int)];
};
This union has two members, both of which are the same length, sizeof(int). We can read and write integer values through the u::i member just as we can any ordinary integer, however the u::c member allows us to read and write the individual bytes within the integer. Since both members are integral types, there is no need to keep track of which member is currently active; it simply provides two methods of accessing the same memory. Thus if we need to access a multi-byte value at the byte level, a union provides the most intuitive method of achieving it without resorting to type casting a pointer.
Where members differ in size, we often need to keep track of which member is active. One method of achieving this is by embedding the union in a struct along with an enum member to keep track of the active member of the union:
typedef enum a_t {num, arr} a;
union u {
int number;
int* array;
};
struct s {
u data;
a active;
};
In the above example, we can choose to store a single value in s::u::number or we can choose to store multiple values in the memory pointed to by s::u::array. However, if we store a value in s::u::number and then attempted to dereference the s::u::array pointer, we incur undefined behaviour because a) an int and a pointer (to any type) are not guaranteed to be the same length and b) the number may not contain a valid address.
Therefore it is important that whenever we write to s::u we update s::a to reflect which member was written to and we must read s::a before accessing s::u. In addition, we must be sure to release any resources currently allocated to the s::u::array before assigning a new value to s::u.
In this example we don't actually gain any benefit by using a union because we end up using just a much memory as we would if the two members were allocated to separate addresses, because of the need to keep track of the active member. However, if the union has three or more members, we begin to save memory because all the "inactive" members cost nothing.
What are the limiting assumptions of C-V-P analysis?
I am interpreting the question as above as Cost Volume Profit(CVP) analysis. If this is not so, my answer below will not be correct. First of all, CVP is used in Finance or Accounting, to describe the behaviour of cost, revenue and profit. Other disciplines also use this analysis, and will be called a different name. In Business Management, it's often called Break Even Analysis. One of limiting assumptions of CVP analysis is the assumption of a linear function of the variable cost and total cost. This means that the cost of a business will increase in a proportional manner, if I make 2 units of output, the cost is 4, if I make 4 units of output, the cost is 8. While this may be possible in theory, it reality, it's not so. If we assume that the cost is linear, the Variable Cost and the Total Cost will be a straight line. In reality, the variable cost doesn't increase in along a straight line. ( not so perfect in reality ). Apart from that, the CVP analysis also assumes that there are no stocks present. The analysis just shows that goods are sold and the company has no stocks kept. Although these can be seen as a limiting assumptions of the CVP analysis, it's important to understand it provides an understanding to students who are new to it. In Economics, the CVP analysis is more complicated, with the variable cost and the total cost function a curve. This means that the cost will fall initially and then increase later. Apart from that in other Ecnomics, costs are considered with the short run and long run perspective. Costs may not be the same in short run and long run.
What was the result of trinity test?
Trinity was the first test of technology for a nuclear weapon. It was conducted by the United States on July 16, 1945, at a location 35 miles (56 km) southeast of Socorro, New Mexico, on what is now White Sands Missile Range, headquartered near Alamogordo. Trinity was a test of an implosion-design plutonium bomb. The Fat Man bomb, using the same conceptual design, was dropped on Nagasaki, Japan, on August 9th. The Trinity detonation was equivalent to the explosion of around 20 kilotons of TNT and is usually considered the beginning of the Atomic Age.
What is the difference between instruction registers and instruction pointer?
instruction register is used to store the next instruction to be executed.
instruction pointer is used to store the address of the next instruction to be executed.
What does a signed data type mean?
signed: its value can be less than zero
unsigned: its value cannot be less than zero
example:
16 bit signed: -32768 .. 32767
16 bit unsigned: 0 .. 65535
Is a global variable a non-local variable?
True, a variable cannot be both global and local. But if a global and a local variable share the same name, the local one will hide the global.
A binary tree with 20 nodes has null branches equals?
A binary tree with n nodes has exactly n+1 null nodes or Null Branches.
so answer is 21.
MOHAMMAD SAJID
How many types of function in C?
Well, it depends on what you mean by the type of a function.
There are user defined functions and library functions.
It is 'flat', and it means unstructured, i.e. it has no segment and offset parts.
In C, there will be a part like this:
char s1[] = "END";
char s2[] = "REVEREND";
size_t l1, l2;
l1= strlen (s1);
l2 = strlen (s2);
if (l1>=l2 && strcmp (s1, s2+(l2-l1))==0) puts ("Yeah");
Which operator is used 2 access ahidden global variables?
To access a hidden global variable, use the scope resolution operator ::
What was the most important capability of C plus plus that C did not provide?
The most important capability is Object Oriented Programming (OOP) principals, which necessitated the inclusion of classes. That was the main reason Bjarne Stroustrup developed C++ in the first place (indeed, C++ was originally called 'C with Classes').
How can a loop be structured so that it terminates a statement in the middle of its block?
I think you want to use statement break.
A capacity swap is what got Qwest and global crossing in trouble with the SEC a few years ago. It basically goes like this: Qwest sells $100,000 in capacity to global crossing In return, global crossing sells $100,000 in capacity to qwest The purchases cancel each other out so no real transaction has taken place Both companies record $100,000 in revenue Clearly these are not really revenues, but it was the result of myopic behavior by the company's CEO's attempting to meet their quotas and in the long run it landed them in hot water
What is my GPA if i have three b's two c's and two a's?
A = 4.0
B = 3.0
C = 2.0
D = 1.0
F = 0.0
Average them.
Write a c program to find factorial non recursive?
/*program for finding the factorial*/
void main()
{
int a,b=1;
clrscr();
printf("Please enter any number to find its factorial\n");
scanf("%d",&a);
while(a>1)
{
b=b*a;
a--;
}
printf("factorial is %d",b);
getch();
}
The simplest way is probably to read the numbers into an array and then prints each element of the array starting at the last one and moving backwards.
A c program to interchange odd and even components of an array?
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,evc=0,odc =0;// sum=0;
clrscr();
printf("enter 10 no.s in the array\n");
for(i=0;i<=9;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=9;i++)
{
if(a[i]%2==0)
{
evc=evc+1;
}
else
{
odc=odc+1;
}
}
printf("Even nos %d\n",evc);
printf("odd nos %d\n",odc);
getch();
}
0"). This is a perfectly valid and correct approach, but in many implementations, a simple test for the least significant bit ("a[i] & 1") can be more efficient. This also allows to replace logic with arithmetic, which generally is more efficient (i.e. "odc += a[i] & 1")
How do you create a calculator using c that tells you if the answer to your problem is even or odd?
Well, you'd start by actually coding the calculator part, but at the end, you would test the answer with something like:
if(ans % 2 == 0) {
printf("%d is even.", ans);
} else {
printf("%d is odd.", ans);
}
The percent sign in the if test is the modulo operator. It returns the remainder of dividing the former argument by the latter argument.
Stack example in c using push and pop?
http://www.osix.net/modules/article/?id=275
muzzy writes "Here's some code for you kids. It demonstrates the concept of stack, implemented with a linked list mechanism to support virtually infinitely large stack sizes. Happy reading."
/* Simple Dynamically Allocating Stack Implementation in C
*
* Copyright (C) 2002 Muzzy of Worst Coders
*/
How do you write a c program to find a2 plus b2 plus 2ab?
{
int a,b;
{
a=a^2;
}
{
b=b^2;
}
{
c=a^2+b^2+2*a*b;
print f("%d%d%d",&c);
get ch();
}
]