Why this C program is crashing?


 
Thread Tools Search this Thread
Top Forums Programming Why this C program is crashing?
# 8  
Old 04-27-2011
Tools

Quote:
Originally Posted by royalibrahim
Hi,

Why I am getting 'SIGSEGV' in the following code?
Code:
char* p="abcde";
printf("%s", 3[p]);     // Segmentation Fault (core dump)

Kindly help me to understand what exactly makes the program to crash or the reason for the crashing.
Hi,

Code:
printf("%s",&3[p]);

3[p] is a character whereas %s needs the address of a character buffer.

Thanks,
Gaurav.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Application keep on crashing need to troubleshoot

Hi experts, I am using RHEL as my distro and I have a very important application running on that server. That application is a third party application and I don't have control with the source. That application keeps on crashing or stop like every other day and it doesn't have any traces on... (1 Reply)
Discussion started by: cwiggler
1 Replies

2. Solaris

Solaris V440 keeps crashing

Hi, I have Sun Solaris V440, every two days or so, the system crashes and it's at OK prompt. After that I do the FSCK and clear all the bad sectors. Then system stays up for close to 48 hours. Then it crashes again. I checked the logs and I don't see anything under /var/adm/messages file. ... (1 Reply)
Discussion started by: samnyc
1 Replies

3. UNIX for Dummies Questions & Answers

Random Crashing

Over the last month or so my CentOS server has been crashing for reasons I do not know. It has been running for over a year with regular yum updates without problems. The load on the server is perfectly normal with CPU usage at 5-6% and RAM usage at less than half of 32GB of RAM (multiple smaller... (3 Replies)
Discussion started by: spinner0205
3 Replies

4. UNIX and Linux Applications

Firefox crashing

Firefox keeps on crashing every time I try to run it. I tried to create a new profile with no luck. When I try to open up the profile manager firefox crashes. I even deleted my profile folder and tried to start with a new profile. That did not work either. I don't know what the problem could be. I... (6 Replies)
Discussion started by: cokedude
6 Replies

5. Web Development

MySQL Server Crashing need Help

Hi, we have some problem with mysql high cpu , would like some help with MySQL Tuning here are the mysqltuner & tuning-primer details mysqltuner: # mysqltuner >> MySQLTuner 1.1.1 - Major Hayden <major@mhtx.net> >> Run with '--help' for additional options and output filtering --------... (1 Reply)
Discussion started by: cataplexy
1 Replies

6. Programming

C++ program is crashing on re-assigning const static member variable using an int pointer

Hi, Can any one tell me why my following program is crashing? #include <iostream> using namespace std; class CA { public: const static int i; }; const int CA::i = 10; int main() { int* pi = const_cast<int*>(&CA::i); *pi = 9; cout << CA::i << endl; } (6 Replies)
Discussion started by: royalibrahim
6 Replies

7. Red Hat

Fedora 11 crashing help

Using Fedora 11, just about every day the system started crashing. Becomes unresponsive to keyboard/mouse, nothing appears on screen but box is still running. Still responds to ping, arp address stays alive in the firewall, other than that its unresponsive Where can I look to find out... (1 Reply)
Discussion started by: ippy98
1 Replies

8. Solaris

Solaris 10 crashing

Hi, My system is crashing with following error .. i tried to boot from the network and unencapsulated the root disk from SVM .. but still not able to boot the box , can any one point me to some direction .. i do not want to build the box new as of now just want to troubleshoot if possible.. ... (3 Replies)
Discussion started by: fugitive
3 Replies

9. Programming

c++ class keeps crashing

i just started learning to prog in c++, im using netbeans. i tryed to make a class and i keep getting this error. what am i doing wrong ? ----------------------------- class test { public: int funtime(); private: int time; }; int test::funtime()... (4 Replies)
Discussion started by: akira300
4 Replies
Login or Register to Ask a Question