answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Write any small program that will compile in C but not in C plus plus?

#include

int main (void)

{

char new [3] = "NEW";

printf ("new='%.3s'\n", new);

return 0;

}

in C++:

int main (void)

{

char newstr [4] = "NEW";

printf ("new='%.3s'\n", newstr);

return 0;

}

How is the old stack pointer value recovered on a function return?

If your stack grows bottom-up, it's decremented when you leave a function; if the stack grows top-down, the stack pointer is incremented.

How is a while loop different from a do until loop in gml?

In any programming language, a "while" loop and a "do until" loop are the same except for 1 difference.

In order to enter a while loop, the condition must always be true.

But in a do until loop, if the condition was false, the block of code inside the loop will always be ran at least once.

Example:

while (false)

{

// code here

}

in this example, the code inside the while loop will never run,

but in the following example:

do

{

//code here

}

until(false)

although the condition is false, the code will be run 1 single time and the exists the loop.

Describe a chicken using a programming language?

chicken is a function which takes argument as grain type and returns egg.

egg chicken(grain x);

Write a c program for binary searching?

/* C program for binary search: This code implements binary search in */

/* C language. It can only be used for sorted arrays, but it's fast as */

/* compared to linear search. If you wish to use binary search on an */

/* array which is not sorted then you must sort it using some sorting */

/* technique say merge sort and then use binary search algorithm to */

/* find the desired element in the list. If the element to be searched */

/* is found then its position is printed. */

#include<stdio.h>

main()

{

int c, first, last, middle, n, search, array[100];

printf("Enter number of elements\n");

scanf("%d",&n);

printf("Enter %d integers\n", n);

for ( c = 0 ; c < n ; c++ )

scanf("%d",&array[c]);

printf("Enter value to find\n");

scanf("%d",&search);

first = 0;

last = n - 1;

middle = (first+last)/2;

while( first <= last )

{

if ( array[middle] < search )

first = middle + 1;

else if ( array[middle] == search )

{

printf("%d found at location %d.\n", search, middle+1);

break;

}

else

last = middle - 1;

middle = (first + last)/2;

}

if ( first > last )

printf("Not found! %d is not present in the list.\n", search);

return 0;

}

Discuss the different formats of floating point numbers?

You can read some details in the Wikipedia article "floating point", especially the "History" section. It isn't worthwhile to copy large amounts of this text here. Nowadays, the most commonly used format is the IEEE 754 format.

Discuss final method and final classes?

a method declared final can not be overridden, and a class declared as final can not be extended by its sub class.

When is the nysc batch c orientation?

Yes, in November 2009. The actual date has not been published yet.

Function to find the transpose of a sparse matrix?

// transpose for the sparse matrix void main() { clrscr(); int a[10][10],b[10][10]; int m,n,p,q,t,col; int i,j; printf("enter the no of row and columns :\n"); scanf("%d %d",&m,&n); // assigning the value of matrix for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("a[%d][%d]= ",i,j); scanf("%d",&a[i][j]); } } printf("\n\n"); //displaying the matrix printf("\n\nThe matrix is :\n\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("%d\t",a[i][j]); } printf("\n"); } t=0; printf("\n\nthe non zero value matrix are :\n\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { // accepting only non zero value if(a[i][j]!=0) { t=t+1; b[t][1]=i; b[t][2]=j; b[t][3]=a[i][j]; } } } printf("a[0 %d %d %d\n",m,n,t); for(i=1;i<=t;i++) { printf("a[%d %d %d %d\n",i,b[i][1],b[i][2],b[i][3]); } a[0][1]=n; a[0][2]=m; a[0][3]=t; int s[10],u[10]; if(t>0) { for(i=1;i<=n;i++) { s[i]=0; } for(i=1;i<=t;i++) { s[b[i][2]]=s[b[i][2]]+1; } u[1]=1; for(i=2;i<=n;i++) { u[i]=u[i-1]+s[i-1]; } for(i=1;i<=t;i++) { j=u[b[i][2]]; a[j][1]=b[i][2]; a[j][2]=b[i][1]; a[j][3]=b[i][3]; u[b[i][2]]=j+1; } } printf("\n\n the fast transpose matrix \n\n"); printf("a[0 %d %d %d\n",n,m,t); for(i=1;i<=t;i++) { printf("a[%d %d %d %d\n",i,a[i][1],a[i][2],a[i][3]); } getch(); }

What is the prototype of a copy constructor for a class X?

class X { public: X(); // default constructor X(const X& x); // copy constructor // ... }; int main(void) { X objx1; //normal ctor X objx2 = x1; // copy ctor X x3(x2); // copy ctor }

What difference does it make if you remove a period in a hash?

It makes a big difference because if you compared the hash:

abcde.fg = hash 1

to

abcdefg = hash 3

The results hash 1 and hash 3 are not equal.

What feature was added to RIP to help with synchronization errors?

RIP_JITTER, from Chapter 4:Distance Vector Routing Protocols. This is found in the "Check Your Understanding" questions, page 214.

Write algorithm for getting ready to come to school?

  1. Wake Up: Set an alarm to wake up at a designated time.
  2. Personal Hygiene: Brush teeth, wash face, and take a shower.
  3. Get Dressed: Choose and put on school clothes, including shoes and accessories.
  4. Breakfast and Pack Bag: Eat a healthy breakfast and pack necessary items like books, homework, and lunch before heading out.

What is the purpose of MD5 hash calculation?

MD5 check sum is unique for a file content and is used to check the integrity of the file content. If file is to be transferred using network, recipient can calculate the MD5 hash and check it with the MD5 check sum of sender, if both are same, he can be sure of non-corruption of file in transit.

What is the error called when it is caused by faulty logic and coding mistakes are?

Error caused by or contributed to by input from operators is called human error.

How do you Send arrays to function?

Simply by sending the base address from main() and catching that in a pointer in the pointer.

void main()

{ int a[20];

sort(a);

}

void fun(int *p)

{

}

What should be the answer given for short term and long term objectives?

Short term objectives are usually based on immediate needs and long term objectives are based on future wants and projected needs.