Archive for the ‘C++ Programming’ Category
Tricky C Programming Interview Questions no comments
There are many companies carrying out projects on C platform. If you have to face an interview in C-programming, it doesn’t mean that you will be working purely on that platform.
But, the fact is that the interviewer will be checking your programming skills based on how you face the interview. Since C-programming is the basic of all programming languages, they expect every technical student to be aware of the basic programming skills.
Here are some of the commonly asked C Programming interview questions –
1. Under basics of C, there are chances of asking the difference between declaration and definition of a variable.
2. Do you think the Global variables will start out as zero?
3. Does C have boolean variable type?
4. Where are the variables defined in C?
5. What does the term storage class refer to?
6. What do you mean by auto, static, volatile, extern, const classes?
7. Do you know anything about typedef keyword?
8. Difference between constants defined through #define and constant keyword?
9. What do you mean by Trigraph characters?
10. How the floating point numbers are stored? What do you mean by IEEE format?
11. When do you think the register modifier will be used?
12. When will you use a type cast?
13. Can structures be assigned to variables and passed to and from functions?
Additionally, be prepared to answer questions on pointers, < malloc > or < calloc> functions, and constructors/destructors if the interviewers jumps on to C++
Operators in C Programming no comments
In C programming language, one can find various operators for performing different kind of operations. There are operators for arithmetic functions, assignment, logical functions, and others.
Operators in C language work on constants and variables, though few are restricted for certain works. Most of the operators are binary; few operators are unary and that takes only one operand.
Arithmetic Operators
Arithmetic operators are used for addition (+), multiplication (*), subtraction (-), and division operations. In addition to these arithmetic operators, there is a modulus operator to give the remainder from the division operator.
Sample Code
1. #include
2.
3. Void main()
4. {
5. int x = 200;
6. int y = 4;
7. int z;
8.
9. z = x + y;
10. printf( “x + y = %dn”, z );
11.
12. c = a – b;
13. printf( “x – y = %dn”, z );
14.
15.
16. printf( “x * y = %dn”, x* y );
17.
18. c = a / b;
19. printf( “x / y = %dn”, z );
20.
21. c = 100 % 3;
22. printf( “x % y = %dn”, z );
23. }
Though the common definition of main() function is nothing but int main(), not many compilers allow main() function to return void. The standard C allows for implementation of defined versions that doesn’t return int.
The output of the above program is:
x + y = 103
x – y = 97
x * y = 300
x / y = 33
x % y = 1
Building a Career as C/C++ Programmer no comments
C/C++ Programming can be really rewarding if you succeed to find the right place to be, and become a C/C++ programmer/developer for a reputed firm. But, if you get stuck at the wrong place, you’ll simply be given the C++ developer label, and in reality you’ll be forced to do things that have simply got nothing to do with your job profile.

The worst part is that after couple of years, nobody will accept you as a C++ developer anymore, because you won’t have the right track record to back the programming abilities that you claim to have (even if you really do!).
Starting Problems!
Another big reason why not too many people really pursue a career as C/C++ developer is that it’s not too easy to get an entry into a corporate with this profile unless you’ve exceptional coding skills… In my initial days, I had tried to get into a hardcore C++ development project for Microsoft, but then I soon realized that I wasn’t that great at network programming and stuff (though I wasn’t bad at coding after all!), and I changed my career path towards Oracle apps. And, I guess that was the right thing to do, because if you get stuck with the wrong job profile, it could mean life-long trouble.
So, better find the right place for yourself, and make sure that you choose a suitable career path; if you’ve got 100% confidence in your C programming skills, then go for it, otherwise building a career as a C++ programmer may not be a great idea in the long run for those who don’t have very strong coding skills.
Adobe Drops Mobile Flash; Concentrates on HTML5 no comments
Adobe recently announced that it is going to discontinue Flash for the mobile browser. Danny Winokur of Adobe went on to confirm the news to ZDNet.

One of the Adobe’s conversations blogs read –
Flash to Focus on PC Browsing and Mobile Apps; Adobe to More Aggressively Contribute to HTML5.
The announcement, however, does not say anything about the unsatisfactory performance of Flash on different mobile browsers. It instead stated that HTML5 is increasingly becoming more and more capable of doing what Flash was capable of. The latter statement is very true, but the fact also remains that Flash enabled phones have showed degraded performance after the different plug-ins installations.
Adobe will be anyway continue working on their cross compiler that helps Flash developers to make native applications that run on different iOS devices. So, it finally proves that Steve Jobs made the right decision of not including Adobe Flash in Apple devices.
The goto statement in c++ no comments
The goto statement in c++
We have gone through the while loop, for loop and do-while loop. The another way to do loop in c++ is through using the goto statement. The goto statement was used in olden days but it is not suitable for creating modern applications. But since c++ supports it, you should have knowledge about it, as you may encounter a c++ source code containing goto statements, in that case you will know what it is and how it works.
How the goto statement works?
It consist of label and statements that comes under that label. A label is named by you and it is followed by a colon sign (:). During execution of program, when goto is encountered, it jumps to the statements that comes under the label specified by goto statement. To get a clear idea, analyze the below program example.
/* A c++ program example that uses goto statement to display number from 0 to 9 */
#include <iostream>
using namespace std;
int main ()
{
int i=0;
loop:
cout << i << endl;
i++;
if (i<10)
goto loop;
return 0;
}
Why goto should not be used?
The use of goto should be avoided to make the program more readable and reliable. The goto statement can cause the program execution to jump to any location in source code and in any direction backward or forward. This makes the program hard to read and understand and also makes it difficult to find bugs.
Since now we have more tightly controlled and sophisticated loops like while loop, for loop and do-while loop, the use of obsolete statement like goto is not at all recommended in creating loops.
What is PMP Certification? no comments
Project Management Professional, commonly known as PMP, is a certification given to those who successfully pass an exam conducted by Project Management Institute (PMI).
Who Offers PMP Certification?
Professional development program is offered by PMI, which is designed based on Project Management Body of Knowledge Guide (PMBOK Guide). The guide contains many proven practices related to project management, constantly evolving innovative techniques, and gain in adopting the techniques.
Why Is It So Important?
In the past, there was no PMP certification. Still, professionals had to manage their projects and work with skills covered by PMP. But, they had no official benchmark to prove their expertise. There came about a necessity of monitoring industry standards. In late 1990’s, the first PMP certification tests emerged focusing on technological fields. The practice had expanded to cover various industries in order to acknowledge the individual’s project management skills.
Why Do You Need The PMP Certification?
You may have an extensive experience in managing projects. While hiring, employers will review work history to make a decision to hire you. The official PMP certification would add more value, and it can help you move one step ahead in your career. Obtaining PMP certification is nothing but proving that you are an expert project manager. It also indicates that you are very serious about the profession and willing to invest time as well as effort to get certifications that are necessary to do the job well. It also saves the prospective employer’s time in researching validity of your work history. Once the PMP certification is obtained, then there is no doubt that you have met industry standards for project management skills.
How Can You Obtain the PMP Certification?
It requires a significant investment in your profession. The candidate must have a minimum of three years of experience in the profession of project management. The candidate is requested to submit specific examples while submitting application.
After reviewing the application, a PMP review board will approve the candidate’s work history. The approved candidate must take up the exam offered by PMI. The examination will be available throughout the world and majority will be from USA. Candidates from Australia, France, UK, and China can take up the exam in their home countries.
Repetition Statement: The Do-While Loop in c++ no comments
Repetition Statement: The Do-While Loop in c++
We have already gone through The While Loop and The For Loop. Now its time for The Do-While Loop.
/* A c++ program example that uses do-while loop to display number from 0 to 9 */
// Program 1
#include <iostream>
using namespace std;
int main ()
{
int i = 0;
do
{
cout << i << endl;
i++;
} while (i < 10);
return 0;
}
The do-while loop works just like the for loop and while loop but with one exception. Unlike the for loop and while loop, the do-while loop will execute at least once.
The for loop and the while loop checks the condition and then the body of loop executes but in case of do-while, the body is executed first and then it checks the condition.
/* A c++ program example that demonstrates how do-while loop distinguishes from the for loop and while loop */
// Program 2
#include <iostream>
using namespace std;
int main ()
{
// The while loop
int i = -1;
while (i != -1)
{
cout << “Inside the while loop. ” << endl;
cout << “Please enter a number or -1 to quit: “;
cin >> i;
}
// The for loop
int j = -1;
for (; j != -1; )
{
cout << “Inside the for loop. ” << endl;
cout << “Please enter a number or -1 to quit: “;
cin >> j;
}
// The do-while loop
int k = -1;
do
{
cout << “Inside the do-while loop. ” << endl;
cout << “Please enter a number or -1 to quit: “;
cin >> k;
} while (k != -1);
return 0;
}
When you run the above program, only the body of do-while gets executed and others do not. The initial value is set to -1 and the condition is such that the value should not be equal to -1. The for loop and while loop checks the condition first and hence their body is not executed, the do-while loop executes the body first and hence it gets executed even though the condition is false, as it checks the condition after executing the body.
Use Do-While when you want the body of the loop to execute at least once, even if the condition is false at the start or else you could make use of the for loop and while loop.
Complex C Programs: Sorting Dates in DD MM YYYY Format no comments
Write a C Program to take any five dates in dd\mm\yyy format, and arrange them in ascending order.
Steps to Develop the Program
1. Dates are entered as strings.
2. Convert the dates into integer values.
3. Check for validation of dates.
4. Sort the dates with respect to their integer values.
5. Display the sorted dates.
To increase the range of dates, we have stored it in 4 bytes using a long integer variable (Under DOS dates are stored in 2 bytes).
So to store the day the lower 5 bytes are used. Now to store a month in next 4 bytes we need to multiply the month by 32.
Similarly, to store the year it is multiplied by 512. This is done because we are required to store the entire date in one single entity, which is later used to sort the dates.
/* Sorting of dates using bubble sort. */
#include < stdio.h >
#include < conio.h >
#include < stdlib.h >
#include < string.h >
int d, m ;
long int y ;
void main( )
{
char dates[5][12], temp[12] ;
long int arr[5], t ;
int i, j, valid ;
int isvalid( ) ;
long int getnum ( char * ) ;
clrscr( ) ;
printf ( “Enter any five dates (dd\mm\yyyy) :-\n” ) ;
for ( i = 0 ; i < = 4 ; i++ )
{
printf(“%d) “,i + 1 ) ;
scanf ( “%s”, dates[i] ) ;
/* Converts date in string to equivalent integer values. */
arr[i] = getnum ( dates[i] ) ;
/* Checks for valid date. */
valid = isvalid( ) ;
if ( !valid )
{
printf ( “This date does not exists. ” ) ;
printf ( “Enter any other date.\n” ) ;
i– ;
}
}
/* Sorting of dates using Bubble sort method. */
for ( i = 0 ; i < = 3 ; i++ )
{
for ( j = 0 ; j < = 3 – i ; j++ )
{
if ( arr[j] > arr[j + 1] )
{
t = arr[j] ;
arr[j] = arr[j + 1] ;
arr[j + 1] = t ;
strcpy ( temp, dates[j] ) ;
strcpy ( dates[j], dates[j + 1]) ;
strcpy ( dates[j + 1], temp ) ;
}
}
}
printf ( “Dates in sorted order are :- \n” ) ;
for ( i = 0 ; i < = 4 ; i++ )
printf ( “%s\n”, dates[i] ) ;
getch( ) ;
}
/* checks valid date */
int isvalid ( )
{
int isleap ( long int ) ;
if ( y < = 0 || m < = 0 || d < = 0 || m > 12 || y > 16384 ||
( m == 2 && !isleap ( y ) && d > 28 ) ||
( m == 2 && isleap ( y ) && d > 29 ) ||
( ( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10
|| m == 12 ) && d > 31 ) || ( ( m == 4 || m == 6 || m == 9 ||
m == 11 ) && d > 30 ) )
return 0 ;
else
return 1 ;
}
/* checks whether the given year is leap or not */
int isleap ( long int y )
{
return ( y % 4 == 0 ) ^ ( y % 100 == 0 ) ^ ( y % 400 == 0 ) ;
}
/* converts dates in string into equivalent integer values */
long int getnum ( char *date )
{
char *p, str[15] ;
long int num = 0 ;
strcpy ( str, date ) ;
d = m = y = 0 ;
p = strtok ( str, “\” ) ;
if ( p != NULL )
d = num = atoi ( p ) ;
p = strtok(NULL, “\”);
if ( p != NULL )
m = atoi ( p ) ;
num += m * 32 ;
p = strtok(NULL, “\”);
if ( p != NULL )
y = atol ( p ) ;
num += y * 512L ;
return num ;
}
Heap Sort in C: Basics & Code Snippet no comments
Few of the sorting techniques like the bubble sort, selection or the insertion sort are good enough for sorting small number of element, while heap sort is used to large number of elements, in a faster way. It’s simple as well, but all it consumes is the additional memory.
Before we get into heap sort technique, let us learn something about the heap data structure, which is used in heap sort. Top element that is present in the heap indicates the next in the line as in the order either it may be highest or the lowest.
Firstly, we will have to create a heap and then go on adding elements to the heap and once you want to delete it then you can easily remove from the heap and in a sorted order as such.
There are two things here one has to worry about –
a. that is the time taken to create the heap, and
b. the time taken to add and remove the element from the heap.
Well, this is quite faster when compared to any of the other sorting techniques.
One of the major disadvantages associated with this technique is that it’s not stable for equal elements, as in it does not preserve the original order. F
or instance if we consider having a list of messages in your inbox then, then you would want the sort by both time and date as well as in an alphabetical order. Then in such cases, you can first sort it as per the date and time and then sort as per the alphabetical order.
Let us illustrate the above scenario with an example:
From: a@qwerty.com sent: 1/1/2011
From: b@qwerty.com sent: 1/1/2011
From: c@qwerty.com sent: 2/9/2009
After sorting using heap sort
From: c@qwerty.com sent: 2/9/2009
From: b@qwerty.com sent: 1/1/2011
From: a@qwerty.com sent: 1/1/2011
As we can see that “b” is ahead of “a” which does not happen in any other sorting techniques as such which indicates that the sort is unstable. A stable sort should look like:
From: c@qwerty.com sent: 2/9/2009
From: a@qwerty.com sent: 1/1/2011
From: b@qwerty.com sent: 1/1/2011
Code Snippet to Implement Heap Sort in C Programming Language
void HSort(int num[], int size)
{
int j, temp;
for (j = (size / 2); j >= 0; j–)
shift(num, j, size – 1);
for (j = size-1; j >= 1; j–)
{
temp = num[0];
num[0] = num[i];
num[i] = temp;
shift(num, 0, i-1);
}
}
void shift(int num [], int head, int tail)
{
int ok, max, temp;
ok = 0;
while ((head*2 <= tail) && (!ok))
{
if (head*2 == tail)
max = head * 2;
else if (num [head * 2] > num [head * 2 + 1])
max= head * 2;
else
max = head * 2 + 1;
if (num [head] < num[max])
{
temp = num[head];
num[head] = num [max];
num[max] = temp;
head = max;
}
else
ok = 1;
}
}
CMS – co to jest i jak z tego korzysta?? no comments
Tworzenie stron WWW w programie Microsoft FrontPage nie jest trudne. Jednak samo utworzenie strony to nie wszystko – nale?y jeszcze utworzone pliki umie?ci? na serwer FTP . Nie nale?y to do rzeczy prostych, zw?aszcza dla osób, które s? ma?o obeznane z komputerami. Dlatego wymy?lono CMSy (ang. Content Manage System) mo?na równie? t?umaczy? to jako: system zarz?dzania tre?ci?.
Takie CMSy charakteryzuj? si? tym, ?e nie musowo zna? j?zyka HTML, wrzuca? pliki na serwer FTP, ani instalowa? na komputerze oprogramowania do tworzenie stron WWW.
CMSy daj? dost?p administratorowi specjaln? stron? internetow? potocznie nazywan? panelem administracyjnym w którym mo?na zarz?dza? tre?ci? strony!
U?ywanie panela administracyjnego nie jest trudne – spor? ilo?? zada? wykonujemy poprzez klikanie mysz?. Z kolei do pisania artyku?u nie musimy zna? HTML-a, gdy? wi?kszo?? CMS-ów udost?pnia posty edytor tekstowy podobny do programu Microsoft Word. Najcz??ciej u?ywane CMSy to: Mambo, Joomla, PHPNuke.
Pewnie si? zastanawiasz dlaczego warto korzysta? z Joomli a ni?eli tworzy? strony internetowe w programie FrontPage. Odpowied? nasuwa si? sama: dobry CMS daje spory komfort.